import requests,re
from lxml import etree
url ='https://www.qidian.com/all_pub'
response = requests.get(url)
root = etree.HTML(response.content)
storys = root.xpath("//div[@class='wrap']/div[@class='cf']/div[@data-l1='5']/div[@class='all-book-list']/div/div/ul/li")
for story in storys:
s_name = story.xpath("div[@class='book-mid-info']/p[@class='author']/span/text()")[0]
print(s_name)
执行结果如下:
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe C:/Users/Administrator/Desktop/python实训/练习.py
Process finished with exit code 0
我的输出语句呢