Coder Social home page Coder Social logo

httpcollector's Introduction

高效爬虫组件 —— httpCollector

适用场景

当有非常多的链接需要爬取时,爬取链接的过程可以交给httpCollector,它可以高效的完成爬取任务,并保证爬取完整的网页内容。利用httpCollector可以取代频繁调用urlopen的情况。

运行环境

实际在 Linux 3.13 内核上测试可正常运行
Linux 2.6 或以上的内核应该也可以运行

运行示例

from httpCollector import HttpCollector

# 加载800个美团店家的URL地址
urls = open("urls.txt", "rb").read().strip().split()

# 用户需要设置每一个http请求对应的header
headers = []
for i in xrange(len(urls)):
	h = "User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/41.0.2272.76 Chrome/41.0.2272.76 Safari/537.36\r\n"
	headers.append(h)

# 开始爬取
(acc_urls, acc_data) = HttpCollector.start(urls, headers)

acc_urls 中保存成功爬取到的URL;
acc_data 中保存服务器返回数据;
acc_urls 和 acc_data 中的元素是一一对应的
注意!:
httpCollector只负责请求并完整接收服务器数据
服务器返回数据包含HTTP协议头部和内容,内容可能是UTF-8编码,可也能经过gzip压缩,需要用户自己查看数据类型并解析

支持

HTTP 1.1 协议中GET请求
HTTP 301HTTP 302重定向

不支持

Https协议
的网页也无法爬取

联系方式

https://github.com/alwaysR9/httpCollector
[email protected]

httpcollector's People

Contributors

alwaysr9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.