import requests #导入请求
from lxml import etree
class Spider(object): #把Spider设置为对象
def start_request(self): #start(开始)
# 1. 请求网站拿到HTML源代码,抽取小说名、小说链接 创建文件夹
response=requests.get(“http://yuedu.sogou.com/category/101”)
#response(反应) requests.get(请求得到源代码)
xml=etree.THML(response.text)
bookname=xml.xpath(’//div[@class=“sort_list_thumb”]/a/img/text()’)
bookweb=xml.xpath(’//div[@class=“sort_list_thumb”]/a/href()’)
print(bookname,bookweb)
spider=Spider()
spider.start_request()
为什么老是错误 环境变量没有配好么 好烦
E:\Python\python.exe E:/Python代码文件夹/demo1.py
Traceback (most recent call last):
File “E:/Python代码文件夹/demo1.py”, line 17, in
spider.start_request()
File “E:/Python代码文件夹/demo1.py”, line 9, in start_request
xml=etree.THML(response.text)
AttributeError: ‘list’ object has no attribute ‘THML’
Process finished with exit code 1