from lxml import html
import requests
page = requests.get('https://projecteuler.net/problem=1')
tree = html.fromstring(page.content)
text=tree.xpath('//div[@class="problem_content"]/text()')
print (text)我有这段代码,因此我想得到描述问题的文本,在本例中:
“如果我们列出所有低于10的自然数,它们是3或5的倍数,我们得到3,5,6和9,这些倍数之和是23。 找出低于1000的3或5倍数之和。“
但相反,我收到的是:
['\r\n', '\n', '\n']发布于 2015-12-23 07:39:36
发现文本本身包含在<p>插槽中,所以xpath行应该像
text=tree.xpath('//div[@role="problem"]/p/text()')https://stackoverflow.com/questions/34430738
复制相似问题