我正在使用xpath制作一个scapy脚本,以收集一些页面信息。 我想提取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如何。也许有一种解决方案,可以在脚本中使用简单的引号...
感谢您的帮助 提醒
答案 0 :(得分:1)
寻找2天后,我找到了答案:D
response.xpath('//div[@class="is-hidden-mobile blEntry menu ui_link"]').re('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+')
我接受所有xpath答案,并使用正则表达式提取URL。
致谢