使用请求和lxml进行html刮取,生成<Element x at location>,而不是位于该节点的文本
回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在创建一个Python程序,使用lxml和请求从网站上抓取文本。但是,当我导航到正确的节点时,我的代码会生成一个元素标签,而不是位于该节点的文本</p>
<pre><code># import packages
from lxml import html
import requests
# initialize program with URL
ficUrl = 'https://www.fanfiction.net/s/10847788/'
# pull metadata
page = requests.get(ficUrl)
tree = html.fromstring(page.content)
title = tree.xpath('//*[@id="profile_top"]/b')
print(title)
</code></pre>
<p>当我检查页面时,应该位于该节点的是文本“Goldstein”。但是,我的程序打印<code>[<Element b at 0x11171e548>]</code>。我能做些什么来解决这个问题</p>