<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>ScrapyTutorial - 标签 | 飞污熊小站</title><link>https://xiongneng.me/tags/scrapytutorial/</link><description>飞污熊小站</description><generator>Hugo 0.161.1 &amp; FixIt v0.4.6-20260512073637-464c4659</generator><language>zh-CN</language><managingEditor>yidao620@163.com (XiongNeng)</managingEditor><webMaster>yidao620@163.com (XiongNeng)</webMaster><copyright>XiongNeng</copyright><lastBuildDate>Sun, 17 May 2026 13:14:48 +0000</lastBuildDate><atom:link href="https://xiongneng.me/tags/scrapytutorial/index.xml" rel="self" type="application/rss+xml"/><item><title>Scrapy笔记12- 抓取动态网站</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-12/</link><pubDate>Fri, 15 Apr 2016 00:38:12 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-12/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;前面我们介绍的都是去抓取静态的网站页面，也就是说我们打开某个链接，它的内容全部呈现出来。
但是如今的互联网大部分的web页面都是动态的，经常逛的网站例如京东、淘宝等，商品列表都是js，并有Ajax渲染，
下载某个链接得到的页面里面含有异步加载的内容，这样再使用之前的方式我们根本获取不到异步加载的这些网页内容。&lt;/p&gt;</description></item><item><title>Scrapy笔记11- 模拟登录</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-11/</link><pubDate>Tue, 12 Apr 2016 00:25:12 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-11/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;有时候爬取网站的时候需要登录，在Scrapy中可以通过模拟登录保存cookie后再去爬取相应的页面。这里我通过登录github然后爬取自己的issue列表来演示下整个原理。&lt;/p&gt;
&lt;p&gt;要想实现登录就需要表单提交，先通过浏览器访问github的登录页面&lt;a href="https://github.com/login" target="_blank" rel="external nofollow noopener noreferrer"&gt;https://github.com/login&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;，然后使用浏览器调试工具来得到登录时需要提交什么东西。&lt;/p&gt;</description></item><item><title>Scrapy笔记10- 动态配置爬虫</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-10/</link><pubDate>Sun, 10 Apr 2016 00:16:12 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-10/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;有很多时候我们需要从多个网站爬取所需要的数据，比如我们想爬取多个网站的新闻，将其存储到数据库同一个表中。我们是不是要对每个网站都得去定义一个Spider类呢？
其实不需要，我们可以通过维护一个规则配置表或者一个规则配置文件来动态增加或修改爬取规则，然后程序代码不需要更改就能实现多个网站爬取。&lt;/p&gt;</description></item><item><title>Scrapy笔记09- 部署</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-09/</link><pubDate>Mon, 21 Mar 2016 00:16:12 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-09/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;本篇主要介绍两种部署爬虫的方案。如果仅仅在开发调试的时候在本地部署跑起来是很容易的，不过要是生产环境，爬虫任务量大，并且持续时间长，那么还是建议使用专业的部署方法。主要是两种方案：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://doc.scrapy.org/en/1.0/topics/deploy.html#deploy-scrapyd" target="_blank" rel="external nofollow noopener noreferrer"&gt;Scrapyd&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 开源方案&lt;/li&gt;
&lt;li&gt;&lt;a href="http://doc.scrapy.org/en/1.0/topics/deploy.html#deploy-scrapy-cloud" target="_blank" rel="external nofollow noopener noreferrer"&gt;Scrapy Cloud&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 云方案&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class="heading-element" id="部署到scrapyd"&gt;&lt;span&gt;部署到Scrapyd&lt;/span&gt;
 &lt;a href="#%e9%83%a8%e7%bd%b2%e5%88%b0scrapyd" class="heading-mark"&gt;
 &lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;
 &lt;/a&gt;
&lt;/h2&gt;&lt;p&gt;&lt;a href="http://doc.scrapy.org/en/1.0/topics/deploy.html#deploy-scrapyd" target="_blank" rel="external nofollow noopener noreferrer"&gt;Scrapyd&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;是一个开源软件，用来运行蜘蛛爬虫。它提供了HTTP
API的服务器，还能运行和监控Scrapy的蜘蛛&lt;/p&gt;</description></item><item><title>Scrapy笔记08- 文件与图片</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-08/</link><pubDate>Sun, 20 Mar 2016 01:16:12 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-08/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;Scrapy为我们提供了可重用的&lt;a href="http://doc.scrapy.org/en/1.0/topics/item-pipeline.html" target="_blank" rel="external nofollow noopener noreferrer"&gt;item pipelines&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;为某个特定的Item去下载文件。
通常来说你会选择使用Files Pipeline或Images Pipeline。&lt;/p&gt;
&lt;p&gt;这两个管道都实现了：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;避免重复下载&lt;/li&gt;
&lt;li&gt;可以指定下载后保存的地方(文件系统目录中,Amazon S3中)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Images Pipeline为处理图片提供了额外的功能：&lt;/p&gt;</description></item><item><title>Scrapy笔记07- 内置服务</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-07/</link><pubDate>Sat, 19 Mar 2016 01:12:12 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-07/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;Scrapy使用Python内置的的日志系统来记录事件日志。&lt;/p&gt;
&lt;p&gt;日志配置&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;LOG_ENABLED = true
LOG_ENCODING = &amp;#34;utf-8&amp;#34;
LOG_LEVEL = logging.INFO
LOG_FILE = &amp;#34;log/spider.log&amp;#34;
LOG_STDOUT = True
LOG_FORMAT = &amp;#34;%(asctime)s [%(name)s] %(levelname)s: %(message)s&amp;#34;
LOG_DATEFORMAT = &amp;#34;%Y-%m-%d %H:%M:%S&amp;#34;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;使用也很简单&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import logging

logger = logging.getLogger(__name__)
logger.warning(&amp;#34;This is a warning&amp;#34;)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;如果在Spider里面使用，那就更简单了，因为logger就是它的一个实例变量&lt;/p&gt;</description></item><item><title>Scrapy笔记06- Item Pipeline</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-06/</link><pubDate>Fri, 18 Mar 2016 01:00:12 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-06/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;当一个item被蜘蛛爬取到之后会被发送给Item Pipeline，然后多个组件按照顺序处理这个item。
每个Item Pipeline组件其实就是一个实现了一个简单方法的Python类。他们接受一个item并在上面执行逻辑，
还能决定这个item到底是否还要继续往下传输，如果不要了就直接丢弃。&lt;/p&gt;</description></item><item><title>Scrapy笔记05- Item详解</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-05/</link><pubDate>Wed, 16 Mar 2016 01:00:15 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-05/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;Item是保存结构数据的地方，Scrapy可以将解析结果以字典形式返回，但是Python中字典缺少结构，在大型爬虫系统中很不方便。&lt;/p&gt;
&lt;p&gt;Item提供了类字典的API，并且可以很方便的声明字段，很多Scrapy组件可以利用Item的其他信息。&lt;/p&gt;</description></item><item><title>Scrapy笔记04- Selector详解</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-04/</link><pubDate>Mon, 14 Mar 2016 02:00:15 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-04/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;在你爬取网页的时候，最普遍的事情就是在页面源码中提取需要的数据，我们有几个库可以帮你完成这个任务：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://www.crummy.com/software/BeautifulSoup/" target="_blank" rel="external nofollow noopener noreferrer"&gt;BeautifulSoup&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;是python中一个非常流行的抓取库,
它还能合理的处理错误格式的标签，但是有一个唯一缺点就是：它运行很慢。&lt;/li&gt;
&lt;li&gt;&lt;a href="http://lxml.de/" target="_blank" rel="external nofollow noopener noreferrer"&gt;lxml&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;是一个基于&lt;a href="https://docs.python.org/2/library/xml.etree.elementtree.html" target="_blank" rel="external nofollow noopener noreferrer"&gt;ElementTree&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;
的XML解析库(同时还能解析HTML),
不过lxml并不是Python标准库&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;而Scrapy实现了自己的数据提取机制，它们被称为选择器，通过&lt;a href="http://www.w3.org/TR/xpath" target="_blank" rel="external nofollow noopener noreferrer"&gt;XPath&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;
或&lt;a href="http://www.w3.org/TR/selectors" target="_blank" rel="external nofollow noopener noreferrer"&gt;CSS&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;表达式在HTML文档中来选择特定的部分&lt;/p&gt;</description></item><item><title>Scrapy笔记03- Spider详解</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-03/</link><pubDate>Sat, 12 Mar 2016 01:19:15 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-03/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;Spider是爬虫框架的核心，爬取流程如下：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;先初始化请求URL列表，并指定下载后处理response的回调函数。初次请求URL通过&lt;code&gt;start_urls&lt;/code&gt;指定，调用&lt;code&gt;start_requests()&lt;/code&gt;
产生&lt;code&gt;Request&lt;/code&gt;对象，然后注册&lt;code&gt;parse&lt;/code&gt;方法作为回调&lt;/li&gt;
&lt;li&gt;在parse回调中解析response并返回字典,&lt;code&gt;Item&lt;/code&gt;对象,&lt;code&gt;Request&lt;/code&gt;对象或它们的迭代对象。&lt;code&gt;Request&lt;/code&gt;
对象还会包含回调函数，之后Scrapy下载完后会被这里注册的回调函数处理。&lt;/li&gt;
&lt;li&gt;在回调函数里面，你通过使用选择器（同样可以使用BeautifulSoup,lxml或其他工具）解析页面内容，并生成解析后的结果Item。&lt;/li&gt;
&lt;li&gt;最后返回的这些Item通常会被持久化到数据库中(
使用&lt;a href="http://doc.scrapy.org/en/latest/topics/item-pipeline.html#topics-item-pipeline" target="_blank" rel="external nofollow noopener noreferrer"&gt;Item Pipeline&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;)
或者使用&lt;a href="http://doc.scrapy.org/en/latest/topics/feed-exports.html#topics-feed-exports" target="_blank" rel="external nofollow noopener noreferrer"&gt;Feed exports&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;将其保存到文件中。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;尽管这个流程适合于所有的蜘蛛，但是Scrapy里面为不同的使用目的实现了一些常见的Spider。下面我们把它们列出来。&lt;/p&gt;</description></item><item><title>Scrapy笔记02- 完整示例</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-02/</link><pubDate>Thu, 10 Mar 2016 09:59:15 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-02/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;这篇文章我们通过一个比较完整的例子来教你使用Scrapy，我选择爬取&lt;a href="http://www.huxiu.com/" target="_blank" rel="external nofollow noopener noreferrer"&gt;虎嗅网首页&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;的新闻列表。&lt;/p&gt;
&lt;p&gt;这里我们将完成如下几个步骤：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;创建一个新的Scrapy工程&lt;/li&gt;
&lt;li&gt;定义你所需要要抽取的Item对象&lt;/li&gt;
&lt;li&gt;编写一个spider来爬取某个网站并提取出所有的Item对象&lt;/li&gt;
&lt;li&gt;编写一个Item Pipline来存储提取出来的Item对象&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Scrapy使用Python语言编写，如果你对这门语言还不熟，请先去学习下基本知识。&lt;/p&gt;</description></item><item><title>Scrapy笔记01- 入门篇</title><link>https://xiongneng.me/posts/python/scrapy/scrapy-01/</link><pubDate>Tue, 08 Mar 2016 10:59:15 +0800</pubDate><author>yidao620@163.com (XiongNeng)</author><guid>https://xiongneng.me/posts/python/scrapy/scrapy-01/</guid><category domain="https://xiongneng.me/categories/python/">Python</category><description>&lt;p&gt;Scrapy是一个为了爬取网站数据，提取结构性数据而编写的应用框架。可以应用在包括数据挖掘，
信息处理或存储历史数据等一系列的程序中。其最初是为了页面抓取(更确切来说,网络抓取)所设计的，
也可以应用在获取API所返回的数据(比如Web Services)或者通用的网络爬虫。&lt;/p&gt;</description></item></channel></rss>