gpt4 book ai didi

python - 使用 Python 向 ASPX 页面提交请求时出错

转载 作者:太空宇宙 更新时间:2023-11-03 18:15:43 24 4
gpt4 key购买 nike

我正在用 Python 试验我的技能,我尝试用 Python 编写一个小脚本,该脚本将使用“网络 whois 记录”选项发送一个请求,以找出该网站位于哪个数据中心

因此我使用了以下网站:

http://centralops.net/co/DomainDossier.aspx

我写了以下脚本:

#!/usr/bin/env python
import urllib2
import urllib

url = "http://centralops.net/co/DomainDossier.aspx"
headers = { 'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml; q=0.9,image/webp,*/*; q=0.8',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection' : 'keep-alaive',
'Accept-Encoding': 'none',
'Accent-Language':'en-US,en;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
}
# All taken from the source page of the website.
FormFields = ((r'_VIEWSTATE',''),(r'addr',r'yahoo.com'),(r'dom_whois','off'),(r'dom_dns','off'),(r'traceroute','off'),(r'net_whois','on'),(r'svc_scan','off'))

encodedFields = urllib.urlencode(FormFields)
req = urllib2.Request(url,encodedFields,headers)
f = urllib2.urlopen(req)

但是当我尝试执行该文件时出现问题,并且出现以下错误:

Traceback (most recent call last):   File "data_center.py", line 18,
in <module>
f = urllib2.urlopen(req) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 127, in urlopen
return _opener.open(url, data, timeout) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 410, in open
response = meth(req, response) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 523, in http_response
'http', request, response, code, msg, hdrs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 448, in error
return self._call_chain(*args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 382, in _call_chain
result = func(*args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Access denie

请问有人可以帮我解决这个问题吗?

提前非常感谢。

最佳答案

正如 Flight Odyssey 所说,他们可能会阻止自动请求。

更改您的代码,使其打印网址而不是提交,并尝试手动粘贴以确保您到达正确的页面 - 可能还有另一个步骤/验证码等。

此外,不确定是否是拼写错误,但您的标题显示

  'Connection' : 'keep-alaive',

关于python - 使用 Python 向 ASPX 页面提交请求时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25050406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com