用python抓取JavaScript中嵌入的数据

2024-05-14 10:18:50 发布

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

我需要在代码javascript中刮取这些数据,我认为我们需要通过js2xml将javascript代码转换成XML数据,问题是它转换所有javascript,例如,如果你想刮取“phone”怎么办。 还有其他解决办法吗?你可以对剧本中的某些词感兴趣。 用途: -python 3.7.0版 -刮1.5 我怎样才能解决这个问题? 谢谢

<script type="text/javascript"> var price = ''; price = price.replace(/ /g ,''); pulse('track', 'trackerEvent', { name: 'Ad detail viewed', type: 'View', object: { type: 'ClassifiedAd', id: '32088977', contentId: '32088977', url: 'https://www.example.com/fr/namecity/accessoires_informatique_et_gadgets/Toner_Heidelberg_Ricoh_C751_C651_32088977.htm?icl=1', name: 'Orgacom sarl', currency:'DH', adType: 'sell', price: Number(price), category: 'INFORMATIQUE ET MULTIMEDIA > Accessoires informatique et Gadgets ', AccountType : 'Pro', location: { type: 'PostalAddress', addressCountry: 'Maroc', City : "Rabat" , Region : 'autre_secteur', }, }, customs: { type: 'Contact', AdID: '40695389', list_id:'32088977', lang:'fr', region: 'Rabat', appl:'vi', categoryID: '5060', Page: 'view_ad ', D2d_offered: 'False' }, actor: email, provider: { productType: 'Web'} }); function ClickPhoneShow() { pulse('track', 'trackerEvent', { name: 'Ad phone number displayed', type: 'Show', action: 'Click', object: { type: 'PhoneContact', id: '32088977', inReplyTo: { id: '32088977', type: 'ClassifiedAd', category: 'INFORMATIQUE ET MULTIMEDIA > Accessoires informatique et Gadgets ', AccountType : 'Pro', name: 'example sarl', phone: '066666666', subject:"Toner Heidelberg Ricoh C751/C651", body:"C751/C651 on met en vente Toner ricoh c751/c651 origine importé d'allemand avec un bon prix <br> (toner + photocopie + ricoh + Heidelberg)<br>contactez nous merci", price: Number(price), location: { type: 'PostalAddress', addressCountry: 'Maroc', City : "Rabat" , Region : 'autre_secteur', }, }, }, target: { type: 'Contact', AdID: '40695389', list_id:'32088977', AdPrice: '', url:'fr/namecitey/accessoires_informatique_et_gadgets/Toner_Heidelberg_Ricoh_C751_C651_32088977.htm ', appl :'vi ', category :'Accessoires informatique et gadgets ', region: 'Rabat', PageType: 'TransactionPage', eventPrefix: 'Phone_Desktop', D2d_offered: 'False' }, actor: email, provider: { productType: 'Web'} }); } </script>

Tags: nameidtypephonefrjavascriptpriceet
1条回答
网友
1楼 · 发布于 2024-05-14 10:18:50

我建议坚持使用js2xml,因为它提供了一种从结构上遍历javascript代码的方法,但当然需要额外的努力。你知道吗

另一种解决方案是使用regex:

phones = re.findall("phone: '(.+)',", script_text)

相关问题 更多 >

    热门问题