0

我想从http://www.site.com/list?a=data&b=data之类的页面获取数据......我从 site.com 的页面检索所有这些 url。尝试打开链接时,出现错误:TypeError: expected BaseHandler instance, got 。

我的猜测是 url 需要“编码”,但如何?

谢谢你们的帮助!


编辑:好的,这是代码,所以所有连接都通过我的代理服务器并尝试打开之前找到的 url,如上所述。

代码:

tileurl = 'http://www.site.com/list?a=data&b=data'
proxy = SocksiPyHandler(socks.PROXY_TYPE_SOCKS4, '192.168.0.190', 12500)
opener = urllib2.build_opener(proxy)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
infile = opener.open(tileurl)
tile_bin = infile.read()

Traceback (most recent call last): 
File "C:\Users\Jean-michel\Dropbox\Projects\Python Code\Maps Saver\map.py", line 89, in <module> opener = urllib2.build_opener(tileurl) 
File "C:\Python27\lib\urllib2.py", line 490, in build_opener opener.add_handler(h) 
File "C:\Python27\lib\urllib2.py", line 326, in add_handler type(handler)) 
TypeError: expected BaseHandler instance, got type 'str' 
4

1 回答 1

0
tileurl = tile.replace(t1, "") ## Removing the parameters from the url
p = urlparse.parse_qs(t1) ## decoding the parameter
tileparam = urllib.urlencode(p) ## encoding the parameter...

问题解决了!!:)

于 2013-07-02T04:28:39.417 回答