python阿里巴巴排名_python使用urllib模块和pyquery实现阿里巴巴排名查询

class ProxyScrapy(object):

def __init__(self):

self.proxy_robot = ProxyRobot()

self.current_proxy = None

self.cookie = cookielib.CookieJar()

def __builder_proxy_cookie_opener(self):

cookie_handler = urllib2.HTTPCookieProcessor(self.cookie)

handlers = [cookie_handler]

if PROXY_ENABLE:

self.current_proxy = ip_port = self.proxy_robot.get_random_proxy()

proxy_handler = urllib2.ProxyHandler({'http': ip_port[7:]})

handlers.append(proxy_handler)

opener = urllib2.build_opener(*handlers)

urllib2.install_opener(opener)

return opener

def get_html_body(self,url):

opener = self.__builder_proxy_cookie_opener()

request=urllib2.Request(url)

#request.add_header("Accept-Encoding", "gzip,deflate,sdch")

#request.add_header("Accept&#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`urlopen`是Python标准库中用于打开URL的函数。在Python3中,它可以通过`urllib.request.urlopen()`来调用。 如果你遇到了`urlopen`报错的问题,以下是一些可能的解决方法: 1. 检查URL是否正确:首先确保你要打开的URL是正确的。如果URL不存在或无法访问,那么`urlopen`函数将会报错。 2. 检查网络连接:如果你的网络连接不稳定或中断,那么`urlopen`函数也会报错。确保你的网络连接正常。 3. 添加User-Agent:有些网站需要在请求头中添加User-Agent才能访问。你可以通过在`urllib.request.Request`中添加headers参数来添加User-Agent。示例代码如下: ```python import urllib.request url = "http://www.example.com" req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'}) response = urllib.request.urlopen(req) ``` 4. 添加超时时间:如果请求时间过长,那么`urlopen`函数也会报错。你可以通过在`urlopen`函数中添加timeout参数来设置超时时间。示例代码如下: ```python import urllib.request url = "http://www.example.com" response = urllib.request.urlopen(url, timeout=5) ``` 5. 检查代理设置:如果你使用了代理服务器来访问网站,那么请确保代理设置正确。你可以通过在`urllib.request.ProxyHandler`中指定代理服务器来设置代理。示例代码如下: ```python import urllib.request proxy_handler = urllib.request.ProxyHandler({'http': 'http://www.example.com:8080/'}) opener = urllib.request.build_opener(proxy_handler) response = opener.open('http://www.example.com') ``` 希望以上方法能帮助你解决`urlopen`报错的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值