import requests
from lxml import etree
import time
class Book():
def init(self):
self.url = “http://www.qingshu.so/lmqs.html”
self.headers = {
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36”
}
def get_data(self):
response = requests.get(url=self.url, headers=self.headers)
response.encoding = "utf-8"
return response.text
def parse(self,data):
tree = etree.HTML(data)
mainlist = tree.xpath('//div[@class="item"]')
fp = open("./烂漫情书.txt", "w", encoding='UTF-8')
for main in mainlist:
mainsrc="http://www.qingshu.so"+ str(main.xpath('.//div[@class="des"]//@href ')[0])
# http://www.qingshu.so/aiqing/1669.html
res=requests.get(mainsrc,headers=self.headers)
res.encoding="utf-8"
res_text=res.text
tree1=etree.HTML(res_text)
h1=tree1.xpath('//h1[@class="a_t

最低0.47元/天 解锁文章
22万+

被折叠的 条评论
为什么被折叠?



