Reputation: 43
I'm making a scapy script, using xpath, to collect some page informations. I would like to extract the URL of the javascript :
<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>
So I test this command :
substring-before(substring-after(//@onclick, "'handlers.onMenuClicked', event, this, '"),"'")
And it works in a Xpath tester.
But when I put it in my python script, I've the quote problem. So I tried to put backslash, but it's not working :
website = response.xpath('substring-before(substring-after(//@onclick, "\'handlers.onMenuClicked\', event, this"),"\'")').extract()
I'm looking on the web, but I dont see any answer :S. I think my script is to complicate and can be simplified, but I dont know how xD. Or maybe there is a solution to have the simple quotes inside the script ...
Thanks for your help REgards
Upvotes: 1
Views: 87
Reputation: 43
After 2 days looking for, I found the answer :D
response.xpath('//div[@class="is-hidden-mobile blEntry menu ui_link"]').re('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+')
I take all the xpath answer, and I extract the URL with a regex.
Regards
Upvotes: 1