python使用urllib模块和pyquery实现阿里巴巴排名查询
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", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") #request.add_header("Cache-Control", "no-cache") #request.add_header("Connection", "keep-alive")
try: response = opener.open(request,timeout=2)
http_code = response.getcode() if http_code == 200: if PROXY_ENABLE: self.proxy_robot.handle_success_proxy(self.current_proxy) html = response.read() return html else: if PROXY_ENABLE: self.proxy_robot.handle_double_proxy(self.current_proxy) return self.get_html_body(url) except Exception as inst: print inst,self.current_proxy self.proxy_robot.handle_double_proxy(self.current_proxy) return self.get_html_body(url)
- python使用urllib模块和pyquery实现阿里巴巴排名查询
- Python 使用urllib2模块实现断点续传下载
- Python使用Com组件及Access查询分析类实现
- Python:使用threading模块实现多线程(转)
- 使用python-whois模块查询域名信息
- 使用python实现短语查询
- 使用Python的SnowNLP模块实现情感分析
- Python中使用urllib2模块编写爬虫的简单上手示例
- Python:使用threading模块实现多线程编程
- Python 使用 OS 模块实现目录遍历
- 享学课堂-在python3中如何使用urllib模块?
- Python:使用threading模块实现多线程编程三[threading.Thread类的重要函数]
- Python中使用urllib2模块编写爬虫的简单上手示例
- 在python中实现生产者和消费者的例子(四):使用thread模块和全局变量
- Python:使用threading模块实现多线程(转)
- python urllib模块的urlopen()的使用方法及实例
- Python多线程 - 使用threading模块实现多线程的 3 种方式
- Python使用文件锁实现进程间同步功能【基于fcntl模块】
- Python使用urllib2模块抓取HTML页面资源的实例分享
- Python:使用threading模块实现多线程编程一[综述]