无法弄清楚电话号码显示的工作原理



我对网页抓取很陌生,最近我正在尝试自动废弃像这样的页面的电话号码。我不应该使用Selenium/headless url浏览器库,我正试图找到一种方法来实际请求电话号码,让我们说一个web服务或任何其他可能的解决方案,可以直接给我电话号码,而不必通过实际按钮按硒。

我完全理解,它可能甚至不可能自动显示电话号码在一个关闭,因为它是不意味着可以访问的八卦新手像我一样的网站刮;但是我还是想提出这个问题,希望从专家的角度得到详细的回答。

如果我搜索"Reveal"按钮DOM元素,它会显示一些我以前从未见过的标签。我有两个问题,我相信对像我这样的新手可能会有帮助。

1)给定一组未知标签/属性(即;数据-q和数据-显示在吹按钮),如何能够找出哪些脚本在页面中实际使用它们?

2)我用谷歌搜索了按钮元素的标签,如:data-q和data-reveal,我能找到的唯一相关的是这个,由于某种原因,我没有访问两个,即使我使用代理。

如果您对第一个问题有任何建议,我将不胜感激。

问候,

下面是按钮代码

<a href="#" class="btn-secondary set-right is-disabled" data-q="reply-panel-reveal-btn" data-reveal="advertId:1190345514" data-analytics="gaEvent:R2SPhoneBegin,zenoEvent:PhoneEvent,zenoOptions:{adId:1190345514,pageType:VIP}" data-toggler="channel:syi.reveal-phone,className:is-disabled,selfBroadcast:false" aria-expanded="true">Reveal</a>

好的,根据你的要求,在你最终得到解决方案之前,有几个步骤。

第一步:打开自己的浏览器,输入目标页面(https://www.gumtree.com/p/vans/2015-ford-transit-custom-2.2tdci-290-l1-h1/1190345514)

第二步:(假设您使用Chrome作为您最喜欢的浏览器)按Ctrl+Shift+I打开控制台,然后在控制台选择'Network'标签。

第三步:按下该页面上的'Reveal'按钮,仔细观察控制台,捕捉到当你按下'Reveal'按钮时立即发送的http请求。您可以在Query string Parameters中看到请求包含一长串数字,实际上它是一个时间戳。

第四步:你也可以看到在那个http请求中有一个名为"Request Headers"的部分,你应该复制referer, user-agent, x-gumtree-token的值。

第五步:试着构造你的请求(我是Python的粉丝,所以我将向你展示我的Python示例代码)
import time
import requests
import json
headers = {
        'referer': 'please enter the value you just copied from that specific request',
        'user-agent': 'please enter the value you just copied from that specific request',
        'x-gumtree-token': 'please enter the value you just copied from that specific request'
    }
url = 'https://www.gumtree.com/ajax/account/seller/reveal/number/1190345514?_='
current_time = time.time()
current_time = str(current_time)
current_time = current_time.split('.')[0] + current_time.split('.')[1] + '0'
url += current_time
response = requests.get(url=url,headers=headers)
response_result = json.loads(response.content)
phone_number = response_result['data']

最新更新