【发布时间】:2017-08-05 00:16:19
【问题描述】:
首先,我对python比较陌生。我需要从网页中的文本中提取链接,我正在使用带有 Python 3.5 的 lxml,但我无法弄清楚。这是我目前所拥有的:
url = someUrl
page = requests.get(url)
webpage = html.fromstring(page.content)
fulllinks = webpage.xpath('//a/@href')
fulltext = webpage.xpath('//a/text()')
for line in fulltext:
if line.startswith("SomethingHere"):
'get the link from SomethingHere and do other stuff'
"somethingHere" 是文本,我想要该文本的链接(例如 www.someweb.com.br/trends)。
我有点迷路了。提前致谢。
【问题讨论】:
标签: python python-3.x text href lxml