python web抓取重定向到其他pag的页面

2024-05-15 06:25:16 发布

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

我在抓取网页内容时遇到了困难。在

下面是我的Python代码:

response = requests.post('http://a836-acris.nyc.gov/bblsearch/bblsearch.asp?borough=1&block=733&lot=66',{'User-Agent' : 'Mozilla/5.0'})

这给了我一个包含表单的HTML页面(不包含最终页面):

^{pr2}$

不过,如果你已经在浏览器中加载了这个网页,那么你就可以在网页中输入这个网页了

enter image description here

任何帮助都将不胜感激!在


Tags: 代码http网页response页面postrequestsgov
1条回答
网友
1楼 · 发布于 2024-05-15 06:25:16

示例中的HTML表显示了需要发布的数据。如我所知,你所使用的URL实际上是referer。所以,你需要:

# 1. Create a payload
payload = {
        'hid_borough': 1,
        'hid_borough_name': 'MANHATTAN / NEW YORK',
        'hid_block': 733,
        'hid_block_value': 733,
        'hid_lot': 66,
        'hid_lot_value': 66,
        'hid_doctype_name': 'All Document Classes',
        'hid_max_rows': 10,
        'hid_page': 1,
        'hid_SearchType': 'BBL',
        'hid_ISIntranet': 'N'
        }

# 2. Add the correct referer to your headers
header = {'User-Agent': 'Mozilla/5.0',
       'referer': 'http://a836-acris.nyc.gov/bblsearch/bblsearch.asp?borough=1&block=733&lot=66'}

# 3. Add payload and headers to the post
redirect = 'https://a836-acris.nyc.gov/DS/DocumentSearch/BBLResult'
result = requests.post(redirect, data=payload, headers=header)

print result.url
https://a836-acris.nyc.gov/DS/DocumentSearch/BBLResult

相关问题 更多 >

    热门问题