下面的代码错在哪里?
import requestsfrom lxml import etree
import openpyxl
wb = openpyxl.Workbook()
ws = wb.active
ws.append(["日期","第一个红球", "第二个红球","第三个红球","第四个红球","第五个红球","第六个红球","蓝球"])
print("请输入开始的期数:",end="")
begin=input("")
print("请输入节束的期数:",end="")
over=input("")
address=("http://datachart.500.com/ssq/history/newinc/history.php?start="+ begin + "&end="+ over)
url = address
response = requests.get(url)
response = response.text
selector = etree.HTML(response)
for i in selector.xpath('//tr[@class="t_tr1"]'):
datetime = i.xpath('td/text()')
red = i.xpath('td/text()')
blue = i.xpath('td/text()')
red.insert(0,datetime)
red.append(blue)
ws.append(red)
wb.save("ball_test.xlsx")
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\001.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests' 上面的代码错在哪里?如何更正? 本帖最后由 松_HWI3H 于 2019-8-27 08:03 编辑
原因:系统检测到没有requests库
解决办法:安装requests库,在cmd中输入pip install requests 就可以了,楼主最好看一下其他库有没有安装,可在cmd中输入pip list查看 是没有安装 requests 库导致的。
安装方法:
1. 打开 Win + R,输入 cmd,进入命令行提示符;
2. 输入 pip install requests,pip 工具会自动给你安装好的。 安装了以后,仍然报错
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\001.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests' 是否同时安装了Python2和Python3? 只安装python3 检查是否配制python环境变量 已配制python环境变量 去到Python安装目录lib下site-packages看一下有没有requests 没有怎么办? C:\Users\Administrator\Desktop\QQ截图20191014223552.jpg
页:
[1]