用表格刮网站

2024-05-20 14:10:24 发布

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

我正试图从这个网站上搜集数据: https://action.labour.org.uk/page/content/council-cuts-calculator

我计划循环浏览一个邮政编码列表,并收集每个邮政编码的信息。你知道吗

我尝试过使用请求模块,如下所示:

import requests
url = 'https://action.labour.org.uk/page/content/council-cuts-calculator'
payload =   {'firstname': 'james',
            'email': 'myemailaddress',
            'zip': 'WS13 6QG',
            'custom_15452': 'no'}
response = requests.post(url, data=payload)
results_text = response.text
soup = BeautifulSoup(results_text, 'html.parser')
print(soup.get_text())

代码运行时没有出现错误,但似乎没有将信息传递给表单,或者至少打印部分不包含与手动输入相同的信息相同的信息。我怀疑这可能是因为它使用的是javascript而不是请求,但不知道如何判断。你知道吗

谁能告诉我用什么方法来获得我想要的信息,下面是一个示例结果。另外,一般来说,你如何判断一个网站表单是否需要请求。获取请求.post或者其他方法?你知道吗

In LICHFIELD, your council will have £68 less to spend on your household by 2020 than they had in 2010.

Under the Tories some of the most deprived areas in the country are hit the hardest, while Tory councils are given a better deal. On average, Tory councils will have £128 less to spend per household, while Labour councils are hit four times harder – losing £524.


Tags: thetexthttpsorg信息网站pageaction
1条回答
网友
1楼 · 发布于 2024-05-20 14:10:24

看起来当您第一次发出POST请求时,还有另一个对https://stats-microapi-production.herokuapp.com发出的immediate GET请求来获取您要查找的数据。你知道吗

结果你可以直接请求 https://stats-microapi-production.herokuapp.com/index.php?campaign=1&pc=WS136QG具有适当的pin码,而无需首先发出POST请求。你知道吗

仅供将来参考,使用mitmproxy或其他替代方法分析浏览器处理的网络数据包很有帮助。你知道吗

相关问题 更多 >