xpath中的转义引号(python脚本)

2024-10-01 05:02:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个scapy脚本,使用xpath来收集一些页面信息。 我想提取javascript的URL:

<div class="is-hidden-mobile blEntry menu ui_link" data-column="3" onclick="widgetEvCall('handlers.onMenuClicked', event, this, 'http://www.zzz.com/')">
    <span class="ui_icon menu"></span>
    <span class="detail">Menu </span>
</div>

所以我测试这个命令:

substring-before(substring-after(//@onclick, "'handlers.onMenuClicked', event, this, '"),"'")

它在Xpath测试程序中工作。你知道吗

但是当我把它放到python脚本中时,我遇到了引用问题。所以我试着用反斜杠,但没用:

website =  response.xpath('substring-before(substring-after(//@onclick, "\'handlers.onMenuClicked\', event, this"),"\'")').extract()

我在网上看,但我没有看到任何答案:S。我认为我的脚本是复杂的,可以简化,但我不知道如何xD。或者也许有一个解决方案,在脚本中有简单的引号。。。你知道吗

谢谢你的帮助 敬礼


Tags: div脚本eventuihandlerssubstringthisxpath
1条回答
网友
1楼 · 发布于 2024-10-01 05:02:12

经过两天的寻找,我找到了答案:D

response.xpath('//div[@class="is-hidden-mobile blEntry menu ui_link"]').re('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+')

我获取所有xpath答案,并用正则表达式提取URL。你知道吗

敬礼

相关问题 更多 >