Use etree and xpath crawling Discuz forum

The introduction module

Download pycharm in lxml library
by from lxml import etreeintroducing modules

test

import requests
from lxml import etree
url = "https://www.discuz.net/forum-developer-1.html"
text = requests.get(url).text
html = etree.HTML(text)
context = etree.tostring(html).decode()
print(html.xpath('//div[@id="threadlist"]/div[2]/form/table/*'))
print(html.xpath('//*[@id="threadlisttableid"]/*'))

Here Insert Picture Description
Here Insert Picture Description
Here are all the forum by xpath syntax of tbodynotes

print(html.xpath('//tbody/tr/th/a[@class="s xst"]/text()'))

Here Insert Picture Description

Published 126 original articles · won praise 35 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_43442524/article/details/103179535