ÓÃprint£¨¡°page2¡±£© ÄÜ¿´µ½Ã¿Ò»ÕµÄÄÚÈÝ[Asm] ´¿Îı¾²é¿´ ¸´ÖÆ´úÂë import requests
import os
from lxml import etree
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
}
url = "https://book.qidian.com/info/1025592578#Catalog"
page_text = requests.get(url=url,headers=headers).text
tree = etree.HTML(page_text)
#½âÎö³öÕ½ÚÃû³ÆºÍÏêÇéÒ³Url
li_list = tree.xpath('//*[@id="j-catalogWrap"]/div[2]/div/ul/li')
if not os.path.exists('./dagelao'):
os.mkdir('./dagelao')
for li in li_list:
detail_url= "https:"+ li.xpath('./a/@href')[0]
name = li.xpath('./a/text()')[0] + ".text"
detaii_page_text = requests.get(url=detail_url,headers=headers).text
detail_tree = etree.HTML(detaii_page_text)
detail_text = detail_tree.xpath('//*[@class="text-wrap"]/div/div[2]//text()')
for page2 in detail_text:
path = './dagelao/' + name
with open(path,"w",encoding="UTF-8") as pf:
pf.write(page2)
print(name,"ÏÂÔØÍê±Ï") |