各位大lao,我这里是因为什么报错呀
# 导包
import requests # 发送网络请求的工具包
from lxml import etree # 转换数据类型
headers = {
# 模拟游览器
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
}
# 设置多个网页,预留更改位置
url = 'https://www.autohome.com.cn/grade/carhtml/%d.html'
# 设置A~Z的选项网页
for i in range(ord("A"), ord("Z") + 1):
U = chr(i)
new_url = "https://www.autohome.com.cn/grade/carhtml/%s.html" % U # 字符串拼接A-Z字母
# new_url = format(url%i)
respone = requests.get(url=new_url, headers=headers) # 发送请求
# print(respone.text)
# 提取我们想要的数据
at = etree.HTML(respone.text)
# print(html_data)
new_url_list = at.xpath('//ul[@class="rank-list-ul"]/li/div/a[@class="red"]/@href')
print(new_url_list)
```python
报错:
Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\pythonProject\qichezhijia.py", line 22, in <module>
new_url_list = at.xpath('//ul[@class="rank-list-ul"]/li/div/a[@class="red"]/@href')
AttributeError: 'NoneType' object has no attribute 'xpath'
```