【发布时间】:2019-09-13 13:07:10
【问题描述】:
我需要获取网页的翻译部分。
这是我的python代码:
import urllib.request
u = urllib.request.urlopen("https://docs.python-guide.org/writing/structure/#structure-of-the-repository")
data = u.read()
from lxml import html
information = html.document_fromstring(data)
for content in information.cssselect('ul li a'):
print(content.text_content())
最后,我也得到了目录部分,我不知道如何过滤信息。
什么是达到此目的的正确方法?
我不得不说我从来没有使用过python,对此我的了解有限。
【问题讨论】:
-
先找到所有
ul,再用第二个得到li a
标签: python parsing css-selectors lxml