我想通过“.cst”文件连接到Web应用装置。如果你想在浏览器中打开它必须键入使用python urllib处理.cst文件/ httplib
http://x.x.x.x/index.cst?Lang=en&login=blafoo&passwd=foobla
如何发送此请求与urllib或其他包?
坦克的帮助
巴斯蒂
我想通过“.cst”文件连接到Web应用装置。如果你想在浏览器中打开它必须键入使用python urllib处理.cst文件/ httplib
http://x.x.x.x/index.cst?Lang=en&login=blafoo&passwd=foobla
如何发送此请求与urllib或其他包?
坦克的帮助
巴斯蒂
import urllib.request
import urllib.parse
params = urllib.parse.urlencode({'Lang': 'en', 'login': 'blafoo', 'passwd': 'foobla'})
f = urllib.request.urlopen("http://x.x.x.x/index.cst?%s" % params)
f.read()
随着urllib
:
import urllib
site = urllib.urlopen('http://x.x.x.x/index.cst?Lang=en&login=blafoo&passwd=foobla')
data = site.read()
此脚本的变量data
将存储你通过了你的网址有什么内容(响应体)。
我建议使用requests(所有时尚的年轻人使用;!),虽然使用urllib
答案已经给出。与要求:
import requests
response = requests.get('http://x.x.x.x/index.cst?Lang=en&login=blafoo&passwd=foobla')
# response.text contains the response contents
# response.status_code gives the response status code (200, 201, 404, etc)
额外的信贷:
import requests
data = {'Lang': 'en', 'login': 'blafoo', 'passwd': 'foobla'}
response = requests.get('http://x.x.x.x/index.cst', params=data)
你有没有试过?问题是什么? – newtover 2012-08-13 12:04:40