只能说找了2个小时 xpath牛逼 css如果出个选择父节点的属性的就好了
import requests
from bs4 import BeautifulSoup
import lxml
from lxml import html
from html.parser import HTMLParser
url='https://www.qidian.com/all?orderId=&style=1&pageSize=20&siteid=1&pubflag=0&hiddenField=0&page=1'
c=requests.get(url)
soup=lxml.etree.HTML(c.text)
tree=soup.xpath("//li[@class='lbf-pagination-item']/a[@class='lbf-pagination-page lbf-pagination-current']/../following-sibling::li[1]")
# 转为string
print(len(tree))
for i in range(len(tree)):
tree1 = html.tostring(tree[i])
# 编码'utf-8'
tree2 = HTMLParser().unescape(tree1.decode('utf-8'))
print(tree2)