开源python爬虫软件下载_WebCollector-Python
WebCollector-Python
WebCollector-Python 是一个无须配置、便于二次开发的 Python 爬虫框架(内核),它提供精简的的 API,只需少量代码即可实现一个功能强大的爬虫。
WebCollector Java版本
WebCollector Java版相比WebCollector-Python具有更高的效率: https://github.com/CrawlScript/WebCollector
安装
pip安装命令
pip install https://github.com/CrawlScript/WebCollector-Python/archive/master.zip
示例
Basic
快速入门
自动探测URL
# coding=utf-8
import webcollector as wc
class NewsCrawler(wc.RamCrawler):
def __init__(self):
super().__init__(auto_detect=True)
self.num_threads = 10
self.add_seed("https://github.blog/")
self.add_regex("+https://github.blog/[0-9]+.*")
self.add_regex("-.*#.*") # do not detect urls that contain "#"
def visit(self, page, detected):
if page.match_url("https://github.blog/[0-9]+.*"):
title = page.select("h1.lh-condensed")[0].text.strip()
content = page.select("div.markdown-body")[0].text.replace("\n", " ").strip()
print("\nURL: ", page.url)
print("TITLE: ", title)
print("CONTENT: ", content[:50], "...")
crawler = NewsCrawler()
crawler.start(10)
手动探测URL
# coding=utf-8
import webcollector as wc
class NewsCrawler(wc.RamCrawler):
def __init__(self):
super().__init__(auto_detect=False)
self.num_threads = 10
self.add_seed("https://github.blog/")
def visit(self, page, detected):
detected.extend(page.links("https://github.blog/[0-9]+.*"))
if page.match_url("https://github.blog/[0-9]+.*"):
title = page.select("h1.lh-condensed")[0].text.strip()
content = page.select("div.markdown-body")[0].text.replace("\n", " ").strip()
print("\nURL: ", page.url)
print("TITLE: ", title)
print("CONTENT: ", content[:50], "...")
crawler = NewsCrawler()
crawler.start(10)
用detected_filter插件过滤探测到的URL
# coding=utf-8
import webcollector as wc
from webcollector.filter import Filter
import re
class RegexDetectedFilter(Filter):
def filter(self, crawl_datum):
if re.fullmatch("https://github.blog/2019-02.*", crawl_datum.url):
return crawl_datum
else:
print("filtered by detected_filter: {}".format(crawl_datum.brief_info()))
return None
class NewsCrawler(wc.RamCrawler):
def __init__(self):
super().__init__(auto_detect=True, detected_filter=RegexDetectedFilter())
self.num_threads = 10
self.add_seed("https://github.blog/")
def visit(self, page, detected):
detected.extend(page.links("https://github.blog/[0-9]+.*"))
if page.match_url("https://github.blog/[0-9]+.*"):
title = page.select("h1.lh-condensed")[0].text.strip()
content = page.select("div.markdown-body")[0].text.replace("\n", " ").strip()
print("\nURL: ", page.url)
print("TITLE: ", title)
print("CONTENT: ", content[:50], "...")
crawler = NewsCrawler()
crawler.start(10)
用RedisCrawler进行可断点的采集(可在关闭后恢复)
# coding=utf-8
from redis import StrictRedis
import webcollector as wc
class NewsCrawler(wc.RedisCrawler):
def __init__(self):
super().__init__(redis_client=StrictRedis("127.0.0.1"),
db_prefix="news",
auto_detect=True)
self.num_threads = 10
self.resumable = True # you can resume crawling after shutdown
self.add_seed("https://github.blog/")
self.add_regex("+https://github.blog/[0-9]+.*")
self.add_regex("-.*#.*") # do not detect urls that contain "#"
def visit(self, page, detected):
if page.match_url("https://github.blog/[0-9]+.*"):
title = page.select("h1.lh-condensed")[0].text.strip()
content = page.select("div.markdown-body")[0].text.replace("\n", " ").strip()
print("\nURL: ", page.url)
print("TITLE: ", title)
print("CONTENT: ", content[:50], "...")
crawler = NewsCrawler()
crawler.start(10)
用Requests定制Http请求
# coding=utf-8
import webcollector as wc
from webcollector.model import Page
from webcollector.plugin.net import HttpRequester
import requests
class MyRequester(HttpRequester):
def get_response(self, crawl_datum):
# custom http request
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36"
}
print("sending request with MyRequester")
# send request and get response
response = requests.get(crawl_datum.url, headers=headers)
# update code
crawl_datum.code = response.status_code
# wrap http response as a Page object
page = Page(crawl_datum,
response.content,
content_type=response.headers["Content-Type"],
http_charset=response.encoding)
return page
class NewsCrawler(wc.RamCrawler):
def __init__(self):
super().__init__(auto_detect=True)
self.num_threads = 10
# set requester to enable MyRequester
self.requester = MyRequester()
self.add_seed("https://github.blog/")
self.add_regex("+https://github.blog/[0-9]+.*")
self.add_regex("-.*#.*") # do not detect urls that contain "#"
def visit(self, page, detected):
if page.match_url("https://github.blog/[0-9]+.*"):
title = page.select("h1.lh-condensed")[0].text.strip()
content = page.select("div.markdown-body")[0].text.replace("\n", " ").strip()
print("\nURL: ", page.url)
print("TITLE: ", title)
print("CONTENT: ", content[:50], "...")
crawler = NewsCrawler()
crawler.start(10)
开源python爬虫软件下载_WebCollector-Python相关推荐
- 手机版python编程软件下载,手机python编程软件
1.求 python 64位安装包下载 软件介绍: python是一款面向对象.解释型.动态数据类型的高级编程设计语言.它拥有语言上的简洁性.可读性和易维护性,在图形处理.数学处理.文本处理.系统编程 ...
- 开源python爬虫软件下载_83款 网络爬虫开源软件
Nutch 是一个开源Java 实现的搜索引擎.它提供了我们运行自己的搜索引擎所需的全部工具.包括全文搜索和Web爬虫. 尽管Web搜索是漫游Internet的基本要求, 但是现有web搜索引擎的数目 ...
- python爬虫软件-从零开始写Python爬虫,四大工具你值得拥有!
如果你正在学习编程,那么"爬虫"绝对是你不可忽视的.那么,学习python爬虫之前需要哪些准备? 一颗热爱学习,不屈不挠的心 一台有键盘的电脑(什么系统都行.我用的os x,所以例 ...
- python中文版软件下载-专业PYTHON开发工具——PyCharm中文汉化版下载(图文)
PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元测试.版本控制. ...
- python在哪下载安装,python软件在哪下载
大家好,小编来为大家解答以下问题,在哪下载python程序,python软件在哪下载,今天让我们一起来看看吧! 1.python在官网怎么下载在d盘 安装步骤如下. 1.在浏览器内输入python官网 ...
- Python爬虫实战——下载小说
Python爬虫实战--下载小说 前言 第三方库的安装 示例代码 效果演示 结尾 前言 使用requests库下载开源网站的小说 注意:本文仅用于学习交流,禁止用于盈利或侵权行为. 操作系统:wind ...
- python中文版软件下载-Python中文版
python中文版是一种面向对象的解释型计算机程序设计语言.python中文版官网面向对象编程,拥有高效的高级数据结构和简单而有效的方法,其优雅的语法.动态类型.以及天然的解释能力,让它成为理想的语言 ...
- python爬虫下载-python爬虫之下载文件的方式总结以及程序实例
python爬虫之下载文件的方式以及下载实例 目录 第一种方法:urlretrieve方法下载 第二种方法:request download 第三种方法:视频文件.大型文件下载 实战演示 第一种方法: ...
- python 下载文件-python爬虫之下载文件的方式总结以及程序实例
python爬虫之下载文件的方式以及下载实例 目录 第一种方法:urlretrieve方法下载 第二种方法:request download 第三种方法:视频文件.大型文件下载 实战演示 第一种方法: ...
最新文章
- 谷歌丰田联合成果ALBERT了解一下:新轻量版BERT,参数小18倍,性能依旧SOTA
- hive删除hbase数据_Hive进阶:Hive通过外部表操作Hbase数据
- python3 with中异常的问题
- 【Groovy】Groovy 动态语言特性 ( Groovy 中函数实参自动类型推断 | 函数动态参数注意事项 )
- 详细设计 存储分配_万字长文:云架构设计原则(一)
- WSGI接口(廖雪峰重点)
- 阿里疯传!Python+Tableau+Excel数分教程(附内部资源)
- stm32 ISP串口下载
- java验证码制作思路_Java实现验证码制作之一自己动手
- HDU-2082 找单词 母函数
- python文件管不了_Python文件_管道与模块编写
- 两个组件对不齐(css样式问题)
- Atitit 知识点的体系化 框架与方法 如何了解 看待xxx
- MAX DotNet 透明界面效果代码实例 转自CG++原帖
- 哈夫曼编码与哈夫曼树
- JAVA(jar)软件_Autojar - 打包工具 - 开发工具 - JAVA开源项目 - 开源吧
- 第十一章:项目风险管理 - (11.4 实施定量风险分析)
- IOS通用链接处理(Universal Links),apple-app-site-association
- mac电脑运行很卡不流畅,如何给mac提速?
- 如何用matlab对两个行向量作图_matlab 绘图与图形处理(二)