scrapy

scrapy爬虫提取网页链接的两种方法以及构造HtmlResponse对象的方式

偶尔善良 提交于 2020-02-12 22:20:58
Response对象的几点说明:   Response对象用来描述一个HTTP响应,Response只是一个基类,根据相应的不同有如下子类:     TextResponse,HtmlResponse,XmlResponse   仅以HtmlResponse为例,HtmlResponse在基类Response的基础上,还多了很多新的方法。 一.使用Selector     因为链接也是页面中的数据,所以可以使用与提取数据相同的方法进行提取。在分析网页时可以通过jupyter notebook构造selector对象进行分析(selector对象有xpath和css方法)       import requests       from scrapy.selector import Selector            res=requests.get("http://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html")       selector=Selector(response=res) 二 . 使用 scrapy框架中的linkextractors模块     用法见相关资料   1. le.extractor_links(response)中的response指的是HtmlResponse

Python爬虫基础

。_饼干妹妹 提交于 2020-02-12 12:18:25
爬取流程 发送请求——获得页面——解析页面——下载内容——储存内容 基础模块 urllib, urllib2, requests, bs4(Beautifulsoup), pyquery 动态页面 selenium(会了这个配合scrapy无往不利) phantomJS(不显示网页的selenium) 解析语言 正则表达式, XPATH, CSS 遇到反爬虫策略验证码之类 tesserocr等 数据库 mysql, mongodb, redis 爬虫框架 scrapy(推荐), pyspider 爬虫架构:调度器,请求队列,代理池,cookie池等 进阶技术 多线程、分布式(结合scrapy) 来源: CSDN 作者: 罗小爬EX 链接: https://blog.csdn.net/luo15242208310/article/details/104222361

Python爬虫5.5 — scrapy框架logging模块的使用

倾然丶 夕夏残阳落幕 提交于 2020-02-12 12:12:05
Python爬虫5.5 — scrapy框架logging模块的使用 综述 log 介绍 关于log等级 logging.getLogger() 日志保存到本地 自定义logger 其他博文链接 综述 本系列文档用于对Python爬虫技术的学习进行简单的教程讲解,巩固自己技术知识的同时,万一一不小心又正好对你有用那就更好了。 Python 版本是3.7.4 本篇文章主要讲解日志模块(logging)的使用。 log 介绍 在第一篇入门文章中我们嫌打印的日志信息过多,稍微对日志设置了一下打印等价: LOG_LEVEL = "WARNING" 仅打印 WARNING 等级及其以上的日志信息。 关于log等级 Scrapy提供5层logging级别: CRITICAL - 严重错误(critical) ERROR - 一般错误(regular errors) WARNING - 警告信息(warning messages) INFO - 一般信息(informational messages) DEBUG - 调试信息(debugging messages) 上述对应等级的信息我们可以分别使用对应的函数进行输出: logging.critical() 、 logging.error() 、 logging.warning() 、 logging.info() 、 logging

Scrapy使用shell调试

有些话、适合烂在心里 提交于 2020-02-08 04:41:34
使用shell尝试爬取 $ scrapy shell https: / / www . zhipin . com / c101280100 / 2020 - 02 - 07 10:42:20 [scrapy.utils.log] INFO: Scrapy 1 . 8 . 0 started ( bot: scrapybot ) 2020 - 02 - 07 10:42:20 [scrapy.utils.log] INFO: Versions: lxml 4 . 5 . 0 . 0 , libxml2 2 . 9 . 10 , cssselect 1 . 1 . 0 , parsel 1 . 5 . 2 , w3lib 1 . 21 . 0 , Twisted 19 . 10 . 0 , Python 3 . 8 . 0 ( v3 . 8 . 0:fa919fdf25 , Oct 14 2019 , 10:23:27 ) - [Clang 6.0 (clang-600.0.57)] , pyOpenSSL 19 . 1 . 0 ( OpenSSL 1 . 1 . 1d 10 Sep 2019 ) , cryptography 2 . 8 , Platform macOS - 10 . 15 . 2 - x86_64 - i386 - 64bit 2020 - 02 - 07 10

第13关. 各司其职的爬虫公司

对着背影说爱祢 提交于 2020-02-08 02:52:41
前两关,我们学习了能提升爬虫速度的进阶知识——协程,并且通过项目实操,将协程运用于抓取薄荷网的食物数据。 icon 可能你在体验开发一个爬虫项目的完整流程时,会有这样的感觉:原来要完成一个完整的爬虫程序需要做这么多琐碎的工作。 icon 比如,要导入不同功能的模块,还要编写各种爬取流程的代码。而且根据不同的项目,每次要编写的代码也不同。 icon 不知道你会不会有这样的想法:能不能有一个现成的爬虫模板,让我们拿来就能套用,就像PPT模板一样。我们不需要管爬虫的全部流程,只要负责填充好爬虫的核心逻辑代码就好。要是有的话,我们编写代码一定会很方便省事。 icon 其实,在Python中还真的存在这样的爬虫模板,只不过它的名字是叫框架。 icon 一个爬虫框架里包含了能实现爬虫整个流程的各种模块,就像PPT模板一开始就帮你设置好了主题颜色和排版方式一样。 icon 这一关,我们要学习的就是一个功能强大的爬虫框架——Scrapy。 Scrapy是什么 以前我们写爬虫,要导入和操作不同的模块,比如requests模块、gevent库、csv模块等。而在Scrapy里,你不需要这么做,因为很多爬虫需要涉及的功能,比如麻烦的异步,在Scrapy框架都自动实现了。 我们之前编写爬虫的方式,相当于在一个个地在拼零件,拼成一辆能跑的车。而Scrapy框架则是已经造好的、现成的车,我们只要踩下它的油门

python爬虫scrapy的LinkExtractor

你离开我真会死。 提交于 2020-02-08 00:17:07
使用背景:   我们通常在爬去某个网站的时候都是爬去每个标签下的某些内容,往往一个网站的主页后面会包含很多物品或者信息的详细的内容,我们只提取某个大标签下的某些内容的话,会显的效率较低,大部分网站的都是按照固定套路(也就是固定模板,把各种信息展示给用户),LinkExtrator就非常适合整站抓取,为什么呢?因为你通过xpath、css等一些列参数设置,拿到整个网站的你想要的链接,而不是固定的某个标签下的一些链接内容,非常适合整站爬取。 1 import scrapy 2 from scrapy.linkextractor import LinkExtractor 3 4 class WeidsSpider(scrapy.Spider): 5 name = "weids" 6 allowed_domains = ["wds.modian.com"] 7 start_urls = ['http://www.gaosiedu.com/gsschool/'] 8 9 def parse(self, response): 10 link = LinkExtractor(restrict_xpaths='//ul[@class="cont_xiaoqu"]/li') 11 links = link.extract_links(response) 12 print(links)

项目整理

徘徊边缘 提交于 2020-02-07 09:09:26
这是本博客系列文章的导航 1. 有趣好玩的python小项目 用mnist数据集训练的手写数字识别 2. 基于Django的教育培训CRM系统 教育培训CRM系统(一):表结构设计 教育培训CRM系统(二):登录与注册 教育培训CRM系统(三):客户列表展示 教育培训CRM系统(四):分页 crm项目源码: https://github.com/winstonfy/Winston_crm 3. 基于Django的线上果蔬商城 线上果蔬商城(一):需求分析 线上果蔬商城(二):表结构设计 3. 基于Django的网课平台(前后端分离) 4. 基于scrapy-elasticsearch的搜索引擎 基于scrapy的搜索引擎(一):爬虫知识回顾 基于scrapy的搜索引擎(二):爬取图片网站 基于scrapy的搜索引擎(三):爬取问答网站 基于scrapy的搜索引擎(四):爬取招聘网站 基于scrapy的搜索引擎(五):反爬突破 基于scrapy的搜索引擎(六):爬虫进阶 基于scrapy的搜索引擎(七):scrapy-redis分布式爬虫 基于scrapy的搜索引擎(八):elasticsearch的使用 基于scrapy的搜索引擎(九):Django搭建搜索网站 基于scrapy的搜索引擎(十):scrapyd部署scrapy项目 5. 基于Flask的移动端租房商城(前后端分离)

Why does this code generate multiple files? I want 1 file with all entries in it

扶醉桌前 提交于 2020-02-06 17:52:30
问题 Im trying to work with both beautifulsoup and xpath and was trying to using the following code, but now im getting 1 file per URL instead of before where i was getting 1 file for all the URLS I just moved over the reading from CSV to get the list of urls and also just added the parsing of the url and response.. but when i run this now i get alot of individual files and in some cases 1 file may actually contain 2 scraped pages data.. so do i need to move my file saving out (indent) import

Why does this code generate multiple files? I want 1 file with all entries in it

北慕城南 提交于 2020-02-06 17:43:11
问题 Im trying to work with both beautifulsoup and xpath and was trying to using the following code, but now im getting 1 file per URL instead of before where i was getting 1 file for all the URLS I just moved over the reading from CSV to get the list of urls and also just added the parsing of the url and response.. but when i run this now i get alot of individual files and in some cases 1 file may actually contain 2 scraped pages data.. so do i need to move my file saving out (indent) import

建立属于自己的scrapy crawl模板

前提是你 提交于 2020-02-06 14:33:49
本人安装PYTHON3.7安装位置:D:\Python\Python37 模板位置:D:\Python\Python37\Lib\site-packages\scrapy\templates\spiders 原来有:basic.tmpl ,crawl.tmpl,csvfeed.tmpl,xmlfeed.tmpl 用idle打开crawl.tmpl(打开类型选择*) 将自己的代码粘贴到文件中,并保存为crawlzj.tmpl 应用: scrapy startproject mynew cd mynew scrapy genspider -t crawlzj mykai baidu.com 则用自己的模板建立了一个爬虫,这样避免了重复代码的输入 来源: https://www.cnblogs.com/xkdn/p/12268540.html