Python web scraper帖子似乎不起作用

时间:2017-10-23 19:57:00

标签: python python-3.x beautifulsoup python-requests

我正在尝试将单个文本数据发布到网页以查找设备的保修状态。每次我尝试这个时,我都会获得200个HTTP响应代码,但结果就好像我点击了一个空NID字段的提交按钮。我确信我错过了一些简单的东西,但它让我望而却步。这是我的Python代码:

 #!python3
import requests
from bs4 import BeautifulSoup
from requests.auth import HTTPBasicAuth

#This URL is the page you actually want to pull down with requests.
REQUEST_URL = 'https://teamroom.tantalus.com/web/city-of-fulton/warranty-lookup'

s = requests.Session()

r = s.get(REQUEST_URL, headers=headers)
print('REQUEST_URL: ',r.status_code)
bsObj = BeautifulSoup(r.text, 'html.parser')
action = bsObj.find('form', id='warrantyLookup').get('action')
nid = {'nid':'0017B1CC64'}
r = s.post(action, data=nid, headers=headers)
print(r)
print('NID LOOKUP POST RESULT: ', r.status_code)
r = s.get(action, headers=headers)
print('NID LOOKUP RESULTS GET: ', r.status_code)
bsObj = BeautifulSoup(r.text, 'html.parser')
warranty = bsObj.find('div', id='successMessages')
print('Warranty Results: ', warranty)
errors = bsObj.find('span', id='nid.errors')
print('Errors: ', errors.text)

1 个答案:

答案 0 :(得分:0)

您是否检查了帖子请求的真实情况?

例如,您可以使用chrome来实现。 现在你需要用python重现那个post请求。

enter image description here