【发布时间】:2017-03-29 15:19:05
【问题描述】:
我正在尝试使用 XPath 从网页中选择文本。检查元素后,我看到this。我正在尝试获取Florida State University。当我右键单击复制 XPath 时,我得到了这个:
//*[@id="clue_J_3_2"]/em
但是,当我运行 python 代码时:
from lxml import html
import requests
game_url = 'http://www.j-archive.com/showgame.php?game_id=5566'
page = requests.get(game_url)
tree = html.fromstring(page.content)
path = '//*[@id="clue_J_3_2"]/em'
print tree.xpath(path)
我得到的输出是[]。我尝试了很多变体,包括:
//*[@id="clue_J_3_2"]/em/text()/*/[@id="clue_J_3_2"]/em//*[@id="clue_J_3_2"]//em[@class="correct_response"]/text()
请告诉我如何修复我的 XPath 以获得我想要的文本!
【问题讨论】: