urllib2

以下是为您整理出来关于【urllib2】合集内容,如果觉得还不错,请帮忙转发推荐。

【urllib2】技术教程文章

python urllib2基本身份验证【代码】

您好我正在尝试使用python使用urllib2访问API URL:import urllib2url = 'https://XXXXXXXXXX.com/' username = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, url, username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) urllib2...

python – 使用urllib2发布数据,重定向和维护cookie【代码】

我在Python中使用urllib2将登录数据发布到网站. 成功登录后,该站点将我的请求重定向到另一个页面.有人可以提供一个简单的代码示例,说明如何使用urllib2在Python中执行此操作吗?我想当我被重定向到另一个页面时,我还需要登录cookie.对? 非常感谢advace.解决方法:首先,获得机械化:http://wwwsearch.sourceforge.net/mechanize/你可以用urllib2做这种东西,但是你会编写大量的样板代码,而且它会有错误. 然后:import mechanizebr = ...

使用urllib2进行Python身份验证【代码】

所以我正在尝试使用python从名为vsearch.cisco.com的站点下载文件 [Python]#Connects to the Cisco Server and Downloads files at the URL specifiedimport urllib2#Define Useful Variablesurl = 'http://vsearch.cisco.com' username = 'xxxxxxxx' password = 'xxxxxxxx' realm = 'CEC'# Begin Making connection# Create a Handler -- Also could be where the error lieshandler = urllib2.HTTPDigestAuthHandler() handler.a...

如何使用python / urllib2重定向后确定最终的URL?【代码】

我需要在python中重定向后获取最终的URL. 有什么好办法呢?解决方法: >>> import urllib2 >>> var = urllib2.urlopen('http://www.stackoverflow.com/') >>> var.geturl() 'https://stackoverflow.com/'

python – 使用urllib2打开persian url域【代码】

我正在尝试打开一个网址http://??????-?????????.???/ ar / news-events / event / future-internet-privacy使用urllib2.urlopen但它总是报告错误. 类似的情况发生在http://??????-?????????.???/ ar …其他页面(中文页面)打开正常. 有什么想法指出我打开这些网址的正确方法?urllib2.urlopen("http://??????-?????????.???/ar/news-events/event/future-internet-privacy").read()urllib2.urlopen('http://??????-?????????.???...

使用Python urllib2 /请求对Google云端硬盘进行身份验证并下载电子表格【代码】

我想下载我在Google云端硬盘中向Google验证的文档(我只希望某些用户能够访问它并且不想在网上发布它). 我尝试过使用请求,但显然我做错了.从浏览器我可以将我的文档下载到该地址https://docs.google.com/spreadsheets/d/\u0026lt;document key> / export?format = xls. 所以在我的python脚本中,我执行以下操作:import os import requests import shutil from requests.auth import HTTPBasicAuthremote = "https://docs.google.co...

Python使用urllib2启动请求时无法使用Tor检查【代码】

通过阅读StackOverflow上的other questions后,我得到了一段Python代码,可以通过Tor代理发出请求:import urllib2 proxy = urllib2.ProxyHandler({'http':'127.0.0.1:8118'}) opener = urllib2.build_opener(proxy) print opener.open('https://check.torproject.org/').read()由于Tor使用TorButton在Firefox中运行良好,我希望它能在Python中正常工作.不幸的是,包含在乱七八糟的HTML中:抱歉.你没有使用Tor.我不确定为什么会这样,或...

python – 使用urllib2进行SOAP POST,但我一直收到错误【代码】

我正在尝试通过SOAP POST进行API调用,而且我一直在努力“TypeError:不是有效的非字符串序列或映射对象.” @ data = urllib.urlencode(values)SM_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><AutotaskIntegrations xmlns="...

当使用python urllib2传递json数据时,Github-api给出404【代码】

我有以下代码,它应该执行在github上创建新下载的第一部分.它应该使用POST发送json数据.jsonstring = '{"name": "test", "size": "4"}' req = urllib2.Request("https://api.github.com/repos/<user>/<repo>/downloads") req.add_header('Authorization', 'token ' + '<token>') result = urllib2.urlopen(req, jsonstring)如果我从urlopen()中删除了jsonstring,它不会失败,并提供可用下载列表.但是,如果我尝试POST json-string,我会...

python – 为什么urllib2的.getcode()方法会在404上崩溃?【代码】

在我使用Lynda的初学Python课程中,它说使用.getcode()从url获取http代码,并且可以在读取数据之前用作测试:webUrl = urllib2.urlopen('http://www.wired.com/tag/magazine-23-05/page/4') print(str(webUrl.getcode())) if (webURL.getcode() == 200):data = webURL.read() else:print 'error'但是,当与上面的404页面一起使用时,它会导致Python退出:Python函数意外终止:HTTP错误404:找不到,所以看起来这一课是完全错误的? 我的...

URLLIB2 - 相关标签