我想通过".cst“文件连接到web设备。如果你想在浏览器中打开它,你必须输入
http://x.x.x.x/index.cst?Lang=en&login=blafoo&passwd=foobla如何使用urllib或其他包发送此请求?
坦克求救
巴斯蒂
发布于 2012-08-13 20:54:33
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()发布于 2012-08-13 20:06:15
使用urllib
import urllib
site = urllib.urlopen('http://x.x.x.x/index.cst?Lang=en&login=blafoo&passwd=foobla')
data = site.read()此脚本的变量data将存储从您传递的URL (响应体)获得的内容。
发布于 2012-08-13 20:54:56
尽管已经给出了使用urllib的答案,但我还是推荐使用requests (所有酷孩子都会用它!;)。对于请求:
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)https://stackoverflow.com/questions/11933944
复制相似问题