gpt4 book ai didi

xpath - 使用xpath/scrapy选择id属性

转载 作者:行者123 更新时间:2023-12-03 17:22:29 25 4
gpt4 key购买 nike

我试图从以下forum url中选择用户名。

但是,当我在scrapy shell中使用以下代码时:

admin:~/workspace/scrapper (master) $ scrapy shell "https://bitcointalk.org/index.php?action=profile;u=22232"
In [1]: response.xpath('//*[@id='bodyarea']/table/tbody/tr/td/table/tbody/tr[2]/td[1]/table/tbody/tr[1]/td[2]')
File "<ipython-input-4-abe70514018b>", line 1
response.xpath('//*[@id='bodyarea']/table/tbody/tr/td/table/tbody/tr[2]/td[1]/table/tbody/tr[1]/td[2]')
^
SyntaxError: invalid syntax


但是,在Chrome中,选择器可以正常工作。

有什么建议我做错了吗?

感谢您的答复!

最佳答案

这是因为引号用法不一致。请注意,您在XPath和XPath中的字符串都使用单引号。

使用任一

'//*[@id="bodyarea"]/table...'


要么

"//*[@id='bodyarea']/table..."

关于xpath - 使用xpath/scrapy选择id属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52754187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com