解析信息在按钮点击时显示。

huangapple go评论67阅读模式
英文:

Parsing info revealed on button click

问题

我尝试解析这个页面: https://www.website.com/details/

有一个电话号码按钮 <a class="btn btn-danger show-number"> 隐藏了电话号码的一部分。点击时,ajax post 请求会带来完整的电话号码。

我怎样能在 Python 中模拟这个 post 请求?


import requests, time, json
from bs4 import BeautifulSoup


headers = {
    &quot;Accept&quot;: &quot;text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7&quot;,
    &quot;User-Agent&quot;: &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36&quot;,
}
s = requests.Session()


response = s.get(
    &quot;https://www.mashina.kg/details/kia-sorento-64631fe26592a662606296&quot;, headers=headers
)

soup = BeautifulSoup(response.text, &quot;lxml&quot;)

英文:

I'm trying to parse this page: https://www.website.com/details/

There is a phone number button <a class="btn btn-danger show-number"> hiding the part of the
phone number. On click, ajax post request brings in the complete phone number.

How can I fake this post request in python?

import requests, time, json
from bs4 import BeautifulSoup

headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
}
s = requests.Session()

response = s.get(
"https://www.mashina.kg/details/kia-sorento-64631fe26592a662606296", headers=headers
)

soup = BeautifulSoup(response.text, "lxml")

答案1

得分: 2

尝试:

import requests
from bs4 import BeautifulSoup

url = 'https://www.mashina.kg/details/kia-sorento-64631fe26592a662606296'

headers = {
    'X-Requested-With': 'XMLHttpRequest'
}

soup = BeautifulSoup(requests.get(url + '/givemereal', headers=headers).content, 'html.parser')
for n in soup.select('.number'):
    print(n.text)

这将打印出电话号码。

英文:

Try:

import requests
from bs4 import BeautifulSoup

url = &#39;https://www.mashina.kg/details/kia-sorento-64631fe26592a662606296&#39;

headers  = {
	&#39;X-Requested-With&#39;: &#39;XMLHttpRequest&#39;
}

soup = BeautifulSoup(requests.get(url + &#39;/givemereal&#39;, headers=headers).content, &#39;html.parser&#39;)
for n in soup.select(&#39;.number&#39;):
	print(n.text)

This will print the telephone numbers.

huangapple
  • 本文由 发表于 2023年5月21日 23:22:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300619.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定