Scrapy框架的使用

作者:李忠林

Github: https://github.com/Leezhonglin

Gitblog: https://leezhonglin.github.io/

本文仅用于学习探讨.

Scrapy框架的使用

Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。

其最初是为了 页面抓取 (更确切来说, 网络抓取 )所设计的, 也可以应用在获取API所返回的数据(例如 Amazon Associates Web Services ) 或者通用的网络爬虫。

本文档将通过介绍Scrapy背后的概念使您对其工作原理有所了解, 并确定Scrapy是否是您所需要的。

当您准备好开始您的项目后,您可以参考 入门教程

1. 如何安装scrapy

macos:

pip install  scrapy

安装完成后进入虚拟环境后.可以使用scarpy命令就能检查是否成功

(venv) lizhonglindeMacBook-Pro:qidianspider lizhonglin$ scrapy
Scrapy 1.5.0 - project: qidianspider

Usage:
  scrapy <command> [options] [args]

Available commands:
  bench         Run quick benchmark test
  check         Check spider contracts
  crawl         Run a spider
  edit          Edit spider
  fetch         Fetch a URL using the Scrapy downloader
  genspider     Generate new spider using pre-defined templates
  list          List available spiders
  parse         Parse URL (using its spider) and print the results
  runspider     Run a self-contained spider (without creating a project)
  settings      Get settings values
  shell         Interactive scraping console
  startproject  Create new project
  version       Print Scrapy version
  view          Open URL in browser, as seen by Scrapy

Use "scrapy  -h" to see more info about a command
(venv) lizhonglindeMacBook-Pro:qidianspider lizhonglin$ 

看到上面这样的结果就表示我们的scrapy已经成功安装了.接下来我们就可以来创建我们的项目了.

创建项目的命令是:

scrapy startproject  qidianspider

项目创建成功后有如下的内容:

qidianspider
    qidianspider
        scrapy.cfg
        __init__.py
        items.py
        middlewares.py
        pipelines.py
        settings.py
        spider
            __init__.py

这些文件的含义分别是:

  • scrapy.py: 项目的配置文件

  • qidianspider: 该项目的python模块

  • qidianspider/items.py: 项目中的item文件

  • qidianspider/middlewares.py:

  • qidianspider/piplines.py:项目中处理数据行为.如:一般结构化的数据持久化

  • qidianspider/settings.py:项目的设置文件

  • qidianspider/spiders/: 放置spider代码的目录

2.创建第一个爬虫项目

有了这些我们就可以开始写我们的第一个爬虫了.

在spiders目录下面创建一个qidian.py的文件



import scrapy
from scrapy.selector import Selector


class qiDianSpider(scrapy.spiders.Spider):
    # 启动项目指定的name参数
    name = 'qidian'
    # 指定爬取的页面
    start_urls = {
        'https://www.qidian.com/',
    }

    def parse(self,response):
        #print(response)
        # 页面源码
        # print(response.body)
        res = Selector(response)
        # 获取对应的菜单名称
        menu_type =  res.xpath('//*[@id="classify-list"]/dl/dd/a/cite/span/i/text()').extract()
        # 获取对应的菜单连接
        menu_type_href = res.xpath('//*[@id="classify-list"]/dl/dd/a/@href').extract()
        # print(menu_type,menu_type_href)
        return items

其包含了一个用于下载的初始URL,如何跟进网页中的链接以及如何分析页面中的内容, 提取生成 item 的方法。

为了创建一个Spider,您必须继承 scrapy.Spider 类, 且定义以下三个属性:

  • name: 用于区别Spider。 该名字必须是唯一的,您不可以为不同的Spider设定相同的名字。

  • start_urls: 包含了Spider在启动时进行爬取的url列表。 因此,第一个被获取到的页面将是其中之一。 后续的URL则从初始的URL获取到的数据中提取。

  • parse() 是spider的一个方法。 被调用时,每个初始URL完成下载后生成的 Response 对象将会作为唯一的参数传递给该函数。 该方法负责解析返回的数据(response data),提取数据(生成item)以及生成需要进一步处理的URL的 Request 对象。

这样我们就成功的用scrapy写了第一个爬虫.

启动我们创建好的爬虫:

scrapy crawl qidian

我们能看见如下的输出:

省略很多行
....
2018-07-02 19:16:06 [scrapy.core.engine] INFO: Spider opened
2018-07-02 19:16:06 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2018-07-02 19:16:06 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2018-07-02 19:16:06 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.qidian.com/robots.txt> (referer: None)
2018-07-02 19:16:06 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.qidian.com/> (referer: None)
['玄幻', '奇幻', '武侠', '仙侠', '都市', '现实', '军事', '历史', '游戏', '体育', '科幻', '灵异', '女生网', '二次元'] ['/xuanhuan', '/qihuan', '/wuxia', '/xianxia', '/dushi', '/xianshi', '/junshi', '/lishi', '/youxi', '/tiyu', '/kehuan', '/lingyi', '//www.qdmm.com/', '/2cy']
2018-07-02 19:16:07 [scrapy.core.scraper] ERROR: Spider must return Request, BaseItem, dict or None, got 'list' in <GET https://www.qidian.com/>
2018-07-02 19:16:07 [scrapy.core.scraper] ERROR: Spider must return Request, BaseItem, dict or None, got 'list' in <GET https://www.qidian.com/>
2018-07-02 19:16:07 [scrapy.core.engine] INFO: Closing spider (finished)
2018-07-02 19:16:07 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
....
省略很多行

可以看到输出的log中包含定义在 start_urls 的初始URL,并且与spider中是一一对应的。在log中可以看到其没有指向其他页面( (referer:None) )。

Scrapy为Spider的 start_urls 属性中的每个URL创建了 scrapy.Request 对象,并将 parse 方法作为回调函数(callback)赋值给了Request。

Request对象经过调度,执行生成 scrapy.http.Response 对象并送回给spider parse() 方法。

3. 提取Item
Selectors选择器简介

从网页中提取数据有很多方法。Scrapy使用了一种基于 XPathCSS 表达式机制: Scrapy Selectors。 关于selector和其他提取机制的信息请参考 Selector文档

这里给出XPath表达式的例子及对应的含义:

  • /html/head/title: 选择HTML文档中 标签内的 </code></span><span> 元素</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">/html/head/title/text()</code></span><span>: 选择上面提到的 </span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);"><title></code></span><span> 元素的文字</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">//td</code></span><span>: 选择所有的 </span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);"><td></code></span><span> 元素</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">//div[@class="mine"]</code></span><span>: 选择所有具有 </span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">class="mine"</code></span><span> 属性的 </span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">div</code></span><span> 元素</span></span></p></li> </ul> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>上边仅仅是几个简单的XPath例子,XPath实际上要比这远远强大的多。 如果您想了解的更多,我们推荐 </span><span><span>这篇XPath教程</span></span><span> 。</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>为了配合XPath,Scrapy除了提供了 </span><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">Selector</code></span></span><span> 之外,还提供了方法来避免每次从response中提取数据时生成selector的麻烦。</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>Selector有四个基本的方法(点击相应的方法可以看到详细的API文档):</span></span></p> <ul class="ul-list" style="color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">xpath()</code></span></span><span>: 传入xpath表达式,返回该表达式所对应的所有节点的selector list列表 。</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">css()</code></span></span><span>: 传入CSS表达式,返回该表达式所对应的所有节点的selector list列表.</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">extract()</code></span></span><span>: 序列化该节点为unicode字符串并返回list。</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">re()</code></span></span><span>: 根据传入的正则表达式对数据进行提取,返回unicode字符串list列表。</span></span></p></li> </ul> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"></span></p> <h5 class="md-end-block md-heading" style="font-size:1em;font-weight:bold;line-height:1.4;width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span>4 . 保存爬虫数据</span></h5> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>最简单的方式的就使用如下方式:</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span></span> <span>scrapy crawl douban -o items.json</span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>该命令将采用 </span><span><span>JSON</span></span><span> 格式对爬取的数据进行序列化,生成 </span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">items.json</code></span><span> 文件。</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>在类似本篇教程里这样小规模的项目中,这种存储方式已经足够。 如果需要对爬取到的item做更多更为复杂的操作,您可以编写 </span><span><span>Item Pipeline</span></span><span> 。 类似于我们在创建项目时对Item做的,用于您编写自己的 </span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">tutorial/pipelines.py</code></span><span> 也被创建。 不过如果您仅仅想要保存item,您不需要实现任何的pipeline。</span></span></p> <h5 class="md-end-block md-heading" style="font-size:1em;font-weight:bold;line-height:1.4;width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span>2, 爬虫案例 </span></h5> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>爬去豆瓣电影top250的电影资源.并存入到Mongodb数据库</span></span></p> <h6 class="md-end-block md-heading" style="font-size:1em;font-weight:bold;line-height:1.4;color:rgb(119,119,119);width:inherit;font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span>2.1建立爬虫目录</span></h6> <ol class="ol-list" style="color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span>添加爬取规则属性rules,这个属性是一个列表,它可以包含多个Rule,每个Rule描述了那些链接需要抓取,那些不需要。这些rule可以有callback,也可以没有。</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span> 爬虫的通常需要在一个网页里面爬去其他的链接,然后一层一层往下爬,scrapy提供了LinkExtractor类用于对网页链接的提取</span></span></p></li> </ol> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>LinkExtractor常用的参数有:</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span><span class="cm-variable" style="color:rgb(0,0,0);">allow:提取满足正则表达式的链接</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">deny:排除正则表达式匹配的链接(优先级高于allow)</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">allow_domains:允许的域名(可以是str或list)deny_domains:排除的域名(可以是str或list)</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">restrict_xpaths:提取满足XPath选择条件的链接(可以是str或list)</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">restrict_css:提取满足css选择条件的链接(可以是str或list)</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">tags:提取指定标签下的链接,默认从a和area中提取(可以是str或list)</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">attrs:提取满足拥有属性的链接,默认为href(类型为list)</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">unique:链接是否去重(类型为boolean)</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">process_value:值处理函数(优先级大于allow)</span></span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>代码如下:</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span></span> <span><span class="cm-keyword" style="color:rgb(119,0,136);">import</span> <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span></span> <span><span class="cm-keyword" style="color:rgb(119,0,136);">from</span> <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">selector</span> <span class="cm-keyword" style="color:rgb(119,0,136);">import</span> <span class="cm-variable" style="color:rgb(0,0,0);">Selector</span></span> <span><span>​</span></span> <span><span class="cm-keyword" style="color:rgb(119,0,136);">from</span> <span class="cm-variable" style="color:rgb(0,0,0);">qidianspider</span>.<span class="cm-property" style="color:rgb(0,0,0);">items</span> <span class="cm-keyword" style="color:rgb(119,0,136);">import</span> <span class="cm-variable" style="color:rgb(0,0,0);">DouBanspiderItem</span></span> <span><span>​</span></span> <span><span>​</span></span> <span><span class="cm-keyword" style="color:rgb(119,0,136);">class</span> <span class="cm-def" style="color:rgb(0,0,255);">DouBanSpider</span>(<span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">spiders</span>.<span class="cm-property" style="color:rgb(0,0,0);">Spider</span>):</span> <span>    <span class="cm-comment" style="color:rgb(170,85,0);"># 创建爬虫名称</span></span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">name</span> = <span class="cm-string" style="color:rgb(170,17,17);">'douban'</span></span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">search</span> = []</span> <span>    <span class="cm-comment" style="color:rgb(170,85,0);"># 创建生成爬取链接</span></span> <span>    <span class="cm-keyword" style="color:rgb(119,0,136);">for</span> <span class="cm-variable" style="color:rgb(0,0,0);">i</span> <span class="cm-keyword" style="color:rgb(119,0,136);">in</span> <span class="cm-builtin" style="color:rgb(51,0,170);">range</span>(<span class="cm-number" style="color:rgb(17,102,68);">0</span>, <span class="cm-number" style="color:rgb(17,102,68);">250</span>, <span class="cm-number" style="color:rgb(17,102,68);">25</span>):</span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">a</span> = <span class="cm-string" style="color:rgb(170,17,17);">'https://movie.douban.com/top250?start=%d&filter='</span> <span class="cm-operator" style="color:rgb(152,26,26);">%</span> <span class="cm-variable" style="color:rgb(0,0,0);">i</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">search</span>.<span class="cm-property" style="color:rgb(0,0,0);">append</span>(<span class="cm-variable" style="color:rgb(0,0,0);">a</span>)</span> <span><span class="cm-tab"> </span><span class="cm-comment" style="color:rgb(170,85,0);"># 指定爬取的页面</span></span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">start_urls</span> = <span class="cm-builtin" style="color:rgb(51,0,170);">set</span>(<span class="cm-variable" style="color:rgb(0,0,0);">search</span>)</span> <span><span>​</span></span> <span>    <span class="cm-keyword" style="color:rgb(119,0,136);">def</span> <span class="cm-def" style="color:rgb(0,0,255);">parse</span>(<span class="cm-variable-2" style="color:rgb(0,85,170);">self</span>, <span class="cm-variable" style="color:rgb(0,0,0);">response</span>):</span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">res</span> = <span class="cm-variable" style="color:rgb(0,0,0);">Selector</span>(<span class="cm-variable" style="color:rgb(0,0,0);">response</span>)</span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">items</span> = <span class="cm-variable" style="color:rgb(0,0,0);">DouBanspiderItem</span>()</span> <span>        <span class="cm-comment" style="color:rgb(170,85,0);"># 获取电影名称</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'name'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">res</span>.<span class="cm-property" style="color:rgb(0,0,0);">xpath</span>(<span class="cm-string" style="color:rgb(170,17,17);">'//*[@id="content"]/div/div[1]/ol/li/div/div[2]/div[1]/a/span[1]/text()'</span>).<span class="cm-property" style="color:rgb(0,0,0);">extract</span>()</span> <span>        <span class="cm-comment" style="color:rgb(170,85,0);"># 获取电影图片</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'avator'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">res</span>.<span class="cm-property" style="color:rgb(0,0,0);">xpath</span>(<span class="cm-string" style="color:rgb(170,17,17);">'//*[@id="content"]/div/div[1]/ol/li/div/div[1]/a/img/@src'</span>).<span class="cm-property" style="color:rgb(0,0,0);">extract</span>()</span> <span>        <span class="cm-comment" style="color:rgb(170,85,0);"># 获取电影导演</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">director_info</span> = <span class="cm-variable" style="color:rgb(0,0,0);">res</span>.<span class="cm-property" style="color:rgb(0,0,0);">xpath</span>(<span class="cm-string" style="color:rgb(170,17,17);">'//*[@id="content"]/div/div[1]/ol/li/div/div[2]/div[2]/p[1]/text()[1]'</span>).<span class="cm-property" style="color:rgb(0,0,0);">extract</span>()</span> <span>        <span class="cm-comment" style="color:rgb(170,85,0);"># 处理导演主演信息</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'director'</span>] = [<span class="cm-variable" style="color:rgb(0,0,0);">info</span>.<span class="cm-property" style="color:rgb(0,0,0);">strip</span>().<span class="cm-property" style="color:rgb(0,0,0);">replace</span>(<span class="cm-string" style="color:rgb(170,17,17);">'\xa0'</span>, <span class="cm-string" style="color:rgb(170,17,17);">''</span>) <span class="cm-keyword" style="color:rgb(119,0,136);">for</span> <span class="cm-variable" style="color:rgb(0,0,0);">info</span> <span class="cm-keyword" style="color:rgb(119,0,136);">in</span> <span class="cm-variable" style="color:rgb(0,0,0);">director_info</span>]</span> <span>        <span class="cm-comment" style="color:rgb(170,85,0);"># 处理电影信息</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">movie_info</span> = <span class="cm-variable" style="color:rgb(0,0,0);">res</span>.<span class="cm-property" style="color:rgb(0,0,0);">xpath</span>(<span class="cm-string" style="color:rgb(170,17,17);">'//*[@id="content"]/div/div[1]/ol/li/div/div[2]/div[2]/p[1]/text()[2]'</span>).<span class="cm-property" style="color:rgb(0,0,0);">extract</span>()</span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">movie_info</span> = [<span class="cm-variable" style="color:rgb(0,0,0);">info</span>.<span class="cm-property" style="color:rgb(0,0,0);">strip</span>().<span class="cm-property" style="color:rgb(0,0,0);">replace</span>(<span class="cm-string" style="color:rgb(170,17,17);">'\xa0'</span>, <span class="cm-string" style="color:rgb(170,17,17);">''</span>) <span class="cm-keyword" style="color:rgb(119,0,136);">for</span> <span class="cm-variable" style="color:rgb(0,0,0);">info</span> <span class="cm-keyword" style="color:rgb(119,0,136);">in</span> <span class="cm-variable" style="color:rgb(0,0,0);">movie_info</span>]</span> <span>        <span class="cm-comment" style="color:rgb(170,85,0);"># 处理年 国家 分类信息</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'year'</span>], <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'country'</span>], <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'classification'</span>] = [], [], []</span> <span>        <span class="cm-keyword" style="color:rgb(119,0,136);">for</span> <span class="cm-variable" style="color:rgb(0,0,0);">info</span> <span class="cm-keyword" style="color:rgb(119,0,136);">in</span> <span class="cm-variable" style="color:rgb(0,0,0);">movie_info</span>:</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'year'</span>].<span class="cm-property" style="color:rgb(0,0,0);">append</span>(<span class="cm-variable" style="color:rgb(0,0,0);">info</span>.<span class="cm-property" style="color:rgb(0,0,0);">split</span>(<span class="cm-string" style="color:rgb(170,17,17);">'/'</span>)[<span class="cm-number" style="color:rgb(17,102,68);">0</span>])</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'country'</span>].<span class="cm-property" style="color:rgb(0,0,0);">append</span>(<span class="cm-variable" style="color:rgb(0,0,0);">info</span>.<span class="cm-property" style="color:rgb(0,0,0);">split</span>(<span class="cm-string" style="color:rgb(170,17,17);">'/'</span>)[<span class="cm-number" style="color:rgb(17,102,68);">1</span>])</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'classification'</span>].<span class="cm-property" style="color:rgb(0,0,0);">append</span>(<span class="cm-variable" style="color:rgb(0,0,0);">info</span>.<span class="cm-property" style="color:rgb(0,0,0);">split</span>(<span class="cm-string" style="color:rgb(170,17,17);">'/'</span>)[<span class="cm-number" style="color:rgb(17,102,68);">2</span>])</span> <span>        <span class="cm-comment" style="color:rgb(170,85,0);"># 评分</span></span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">items</span>[<span class="cm-string" style="color:rgb(170,17,17);">'rate'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">res</span>.<span class="cm-property" style="color:rgb(0,0,0);">xpath</span>(<span class="cm-string" style="color:rgb(170,17,17);">'//*[@id="content"]/div/div[1]/ol/li/div/div[2]/div[2]/div/span[2]/text()'</span>).<span class="cm-property" style="color:rgb(0,0,0);">extract</span>()</span> <span>        <span class="cm-keyword" style="color:rgb(119,0,136);">return</span> <span class="cm-variable" style="color:rgb(0,0,0);">items</span></span> <span><span>​</span></span></pre> <h6 class="md-end-block md-heading" style="font-size:1em;font-weight:bold;line-height:1.4;color:rgb(119,119,119);width:inherit;font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span>2.2 Items</span></h6> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>爬取的主要目标就是从非结构性的数据源提取结构性数据,例如网页。 Scrapy提供 </span><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">Item</code></span></span><span> 类来满足这样的需求。</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">Item</code></span></span><span> 对象是种简单的容器,保存了爬取到得数据。 其提供了 </span><span><span>类似于词典(dictionary-like)</span></span><span> 的API以及用于声明可用字段的简单语法。</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>在</span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">itmes.py</code></span><span>文件中声明item,Item使用简单的class定义语法以及 </span><span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">Field</code></span></span><span> 对象来声明。例如:</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span><span class="cm-keyword" style="color:rgb(119,0,136);">import</span> <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span></span> <span><span>​</span></span> <span><span>​</span></span> <span><span class="cm-keyword" style="color:rgb(119,0,136);">class</span> <span class="cm-def" style="color:rgb(0,0,255);">DouBanspiderItem</span>(<span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Item</span>):</span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">name</span> = <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Field</span>()</span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">avator</span> = <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Field</span>()</span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">director</span> = <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Field</span>()</span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">year</span> = <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Field</span>()</span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">country</span> = <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Field</span>()</span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">classification</span> = <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Field</span>()</span> <span>    <span class="cm-variable" style="color:rgb(0,0,0);">rate</span> = <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">Field</span>()</span> <span><span>​</span></span></pre> <h6 class="md-end-block md-heading" style="font-size:1em;font-weight:bold;line-height:1.4;color:rgb(119,119,119);width:inherit;font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span>2.3 Item Pipeline</span></h6> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>当Item在Spider中被收集之后,它将会被传递到Item Pipeline,一些组件会按照一定的顺序执行对Item的处理。</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>每个item pipeline组件(有时称之为“Item Pipeline”)是实现了简单方法的Python类。他们接收到Item并通过它执行一些行为,同时也决定此Item是否继续通过pipeline,或是被丢弃而不再进行处理。</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>以下是item pipeline的一些典型应用:</span></span></p> <ul class="ul-list" style="color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span>清理HTML数据</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span>验证爬取的数据(检查item包含某些字段)</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span>查重(并丢弃)</span></span></p></li> <li class="md-list-item"><p style="width:inherit;"><span class="md-line md-end-block"><span>将爬取结果保存到数据库中</span></span></p></li> </ul> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>写下面的代码前先去</span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">setting.py</code></span><span>文件下写入如下配置:</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span><span class="cm-variable" style="color:rgb(0,0,0);">MONGODB_HOST</span> = <span class="cm-string" style="color:rgb(170,17,17);">'127.0.0.1'</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">MONGODB_PORT</span> = <span class="cm-number" style="color:rgb(17,102,68);">27017</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">MONGODB_DB</span> = <span class="cm-string" style="color:rgb(170,17,17);">'douban'</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">MONGODB_COLLECTION</span> = <span class="cm-string" style="color:rgb(170,17,17);">'movie'</span></span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>写完上面的代码后我们在写如下的代码. 这样我们可以把重要的配置都放入一个固定的位置方便我们管理.</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span><span class="cm-keyword" style="color:rgb(119,0,136);">import</span> <span class="cm-variable" style="color:rgb(0,0,0);">pymongo</span></span> <span><span class="cm-keyword" style="color:rgb(119,0,136);">from</span> <span class="cm-variable" style="color:rgb(0,0,0);">scrapy</span>.<span class="cm-property" style="color:rgb(0,0,0);">conf</span> <span class="cm-keyword" style="color:rgb(119,0,136);">import</span> <span class="cm-variable" style="color:rgb(0,0,0);">settings</span></span> <span><span>​</span></span> <span><span>​</span></span> <span><span class="cm-keyword" style="color:rgb(119,0,136);">class</span> <span class="cm-def" style="color:rgb(0,0,255);">DouBanspiderPipeline</span>(<span class="cm-builtin" style="color:rgb(51,0,170);">object</span>):</span> <span><span>​</span></span> <span>    <span class="cm-keyword" style="color:rgb(119,0,136);">def</span> <span class="cm-def" style="color:rgb(0,0,255);">__init__</span>(<span class="cm-variable-2" style="color:rgb(0,85,170);">self</span>):</span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">conn</span> = <span class="cm-variable" style="color:rgb(0,0,0);">pymongo</span>.<span class="cm-property" style="color:rgb(0,0,0);">MongoClient</span>(<span class="cm-variable" style="color:rgb(0,0,0);">host</span>=<span class="cm-variable" style="color:rgb(0,0,0);">settings</span>[<span class="cm-string" style="color:rgb(170,17,17);">'MONGODB_HOST'</span>], <span class="cm-variable" style="color:rgb(0,0,0);">port</span>=<span class="cm-variable" style="color:rgb(0,0,0);">settings</span>[<span class="cm-string" style="color:rgb(170,17,17);">'MONGODB_PORT'</span>])</span> <span>        <span class="cm-variable" style="color:rgb(0,0,0);">db</span> = <span class="cm-variable" style="color:rgb(0,0,0);">conn</span>[<span class="cm-variable" style="color:rgb(0,0,0);">settings</span>[<span class="cm-string" style="color:rgb(170,17,17);">'MONGODB_DB'</span>]]</span> <span>        <span class="cm-variable-2" style="color:rgb(0,85,170);">self</span>.<span class="cm-property" style="color:rgb(0,0,0);">collection</span> = <span class="cm-variable" style="color:rgb(0,0,0);">db</span>[<span class="cm-variable" style="color:rgb(0,0,0);">settings</span>[<span class="cm-string" style="color:rgb(170,17,17);">'MONGODB_COLLECTION'</span>]]</span> <span><span>​</span></span> <span>    <span class="cm-keyword" style="color:rgb(119,0,136);">def</span> <span class="cm-def" style="color:rgb(0,0,255);">process_item</span>(<span class="cm-variable-2" style="color:rgb(0,85,170);">self</span>, <span class="cm-variable" style="color:rgb(0,0,0);">item</span>, <span class="cm-variable" style="color:rgb(0,0,0);">spider</span>):</span> <span>        <span class="cm-keyword" style="color:rgb(119,0,136);">for</span> <span class="cm-variable" style="color:rgb(0,0,0);">i</span> <span class="cm-keyword" style="color:rgb(119,0,136);">in</span> <span class="cm-builtin" style="color:rgb(51,0,170);">range</span>(<span class="cm-builtin" style="color:rgb(51,0,170);">len</span>(<span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'name'</span>])):</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span> = {}</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span>[<span class="cm-string" style="color:rgb(170,17,17);">'name'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'name'</span>][<span class="cm-variable" style="color:rgb(0,0,0);">i</span>]</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span>[<span class="cm-string" style="color:rgb(170,17,17);">'avator'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'avator'</span>][<span class="cm-variable" style="color:rgb(0,0,0);">i</span>]</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span>[<span class="cm-string" style="color:rgb(170,17,17);">'director'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'director'</span>][<span class="cm-variable" style="color:rgb(0,0,0);">i</span>]</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span>[<span class="cm-string" style="color:rgb(170,17,17);">'year'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'year'</span>][<span class="cm-variable" style="color:rgb(0,0,0);">i</span>]</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span>[<span class="cm-string" style="color:rgb(170,17,17);">'country'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'country'</span>][<span class="cm-variable" style="color:rgb(0,0,0);">i</span>]</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span>[<span class="cm-string" style="color:rgb(170,17,17);">'classification'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'classification'</span>][<span class="cm-variable" style="color:rgb(0,0,0);">i</span>]</span> <span>            <span class="cm-variable" style="color:rgb(0,0,0);">data</span>[<span class="cm-string" style="color:rgb(170,17,17);">'rate'</span>] = <span class="cm-variable" style="color:rgb(0,0,0);">item</span>[<span class="cm-string" style="color:rgb(170,17,17);">'rate'</span>][<span class="cm-variable" style="color:rgb(0,0,0);">i</span>]</span> <span>            <span class="cm-comment" style="color:rgb(170,85,0);"># print(data)</span></span> <span>            <span class="cm-variable-2" style="color:rgb(0,85,170);">self</span>.<span class="cm-property" style="color:rgb(0,0,0);">collection</span>.<span class="cm-property" style="color:rgb(0,0,0);">insert</span>(<span class="cm-variable" style="color:rgb(0,0,0);">data</span>)</span> <span>        <span class="cm-keyword" style="color:rgb(119,0,136);">return</span> <span class="cm-variable" style="color:rgb(0,0,0);">item</span></span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>写完这些后我们的代码就告一段落了.接下来我们需要检查我们的mongodb数据库中是否有我们要存的数据库和</span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">collection</code></span><span>.</span></span></p> <h6 class="md-end-block md-heading" style="font-size:1em;font-weight:bold;line-height:1.4;color:rgb(119,119,119);width:inherit;font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span>2.4 检查数据库</span></h6> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>在我们本地的终端中输入</span><span><code style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;border:1px solid rgb(221,221,221);background-color:rgb(248,248,248);">mongo</code></span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span><span class="cm-variable" style="color:rgb(0,0,0);">lizhonglindeMacBook</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-variable" style="color:rgb(0,0,0);">Pro</span>:<span class="cm-operator" style="color:rgb(152,26,26);">~</span> <span class="cm-variable" style="color:rgb(0,0,0);">lizhonglin</span><span class="cm-error" style="color:#FF0000;">$</span> <span class="cm-variable" style="color:rgb(0,0,0);">mongo</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">MongoDB</span> <span class="cm-variable" style="color:rgb(0,0,0);">shell</span> <span class="cm-variable" style="color:rgb(0,0,0);">version</span> <span class="cm-variable" style="color:rgb(0,0,0);">v3</span><span class="cm-number" style="color:rgb(17,102,68);">.6.5</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">connecting</span> <span class="cm-variable" style="color:rgb(0,0,0);">to</span>: <span class="cm-variable" style="color:rgb(0,0,0);">mongodb</span>:<span class="cm-operator" style="color:rgb(152,26,26);">//</span><span class="cm-number" style="color:rgb(17,102,68);">127.0.0.1</span>:<span class="cm-number" style="color:rgb(17,102,68);">27017</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">MongoDB</span> <span class="cm-variable" style="color:rgb(0,0,0);">server</span> <span class="cm-variable" style="color:rgb(0,0,0);">version</span>: <span class="cm-number" style="color:rgb(17,102,68);">3.6.5</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">Server</span> <span class="cm-variable" style="color:rgb(0,0,0);">has</span> <span class="cm-variable" style="color:rgb(0,0,0);">startup</span> <span class="cm-variable" style="color:rgb(0,0,0);">warnings</span>: </span> <span><span class="cm-number" style="color:rgb(17,102,68);">2018</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">7</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">1</span><span class="cm-variable" style="color:rgb(0,0,0);">T09</span>:<span class="cm-number" style="color:rgb(17,102,68);">41</span>:<span class="cm-number" style="color:rgb(17,102,68);">06.676</span><span class="cm-operator" style="color:rgb(152,26,26);">+</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">800</span> <span class="cm-variable" style="color:rgb(0,0,0);">I</span> <span class="cm-variable" style="color:rgb(0,0,0);">CONTROL</span> [<span class="cm-variable" style="color:rgb(0,0,0);">initandlisten</span>] </span> <span><span class="cm-number" style="color:rgb(17,102,68);">2018</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">7</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">1</span><span class="cm-variable" style="color:rgb(0,0,0);">T09</span>:<span class="cm-number" style="color:rgb(17,102,68);">41</span>:<span class="cm-number" style="color:rgb(17,102,68);">06.676</span><span class="cm-operator" style="color:rgb(152,26,26);">+</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">800</span> <span class="cm-variable" style="color:rgb(0,0,0);">I</span> <span class="cm-variable" style="color:rgb(0,0,0);">CONTROL</span> [<span class="cm-variable" style="color:rgb(0,0,0);">initandlisten</span>] <span class="cm-operator" style="color:rgb(152,26,26);">**</span> <span class="cm-variable" style="color:rgb(0,0,0);">WARNING</span>: <span class="cm-variable" style="color:rgb(0,0,0);">Access</span> <span class="cm-variable" style="color:rgb(0,0,0);">control</span> <span class="cm-keyword" style="color:rgb(119,0,136);">is</span> <span class="cm-keyword" style="color:rgb(119,0,136);">not</span> <span class="cm-variable" style="color:rgb(0,0,0);">enabled</span> <span class="cm-keyword" style="color:rgb(119,0,136);">for</span> <span class="cm-variable" style="color:rgb(0,0,0);">the</span> <span class="cm-variable" style="color:rgb(0,0,0);">database</span>.</span> <span><span class="cm-number" style="color:rgb(17,102,68);">2018</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">7</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">1</span><span class="cm-variable" style="color:rgb(0,0,0);">T09</span>:<span class="cm-number" style="color:rgb(17,102,68);">41</span>:<span class="cm-number" style="color:rgb(17,102,68);">06.676</span><span class="cm-operator" style="color:rgb(152,26,26);">+</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">800</span> <span class="cm-variable" style="color:rgb(0,0,0);">I</span> <span class="cm-variable" style="color:rgb(0,0,0);">CONTROL</span> [<span class="cm-variable" style="color:rgb(0,0,0);">initandlisten</span>] <span class="cm-operator" style="color:rgb(152,26,26);">**</span>          <span class="cm-variable" style="color:rgb(0,0,0);">Read</span> <span class="cm-keyword" style="color:rgb(119,0,136);">and</span> <span class="cm-variable" style="color:rgb(0,0,0);">write</span> <span class="cm-variable" style="color:rgb(0,0,0);">access</span> <span class="cm-variable" style="color:rgb(0,0,0);">to</span> <span class="cm-variable" style="color:rgb(0,0,0);">data</span> <span class="cm-keyword" style="color:rgb(119,0,136);">and</span> <span class="cm-variable" style="color:rgb(0,0,0);">configuration</span> <span class="cm-keyword" style="color:rgb(119,0,136);">is</span> <span class="cm-variable" style="color:rgb(0,0,0);">unrestricted</span>.</span> <span><span class="cm-number" style="color:rgb(17,102,68);">2018</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">7</span><span class="cm-operator" style="color:rgb(152,26,26);">-</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">1</span><span class="cm-variable" style="color:rgb(0,0,0);">T09</span>:<span class="cm-number" style="color:rgb(17,102,68);">41</span>:<span class="cm-number" style="color:rgb(17,102,68);">06.676</span><span class="cm-operator" style="color:rgb(152,26,26);">+</span><span class="cm-error" style="color:#FF0000;">0</span><span class="cm-number" style="color:rgb(17,102,68);">800</span> <span class="cm-variable" style="color:rgb(0,0,0);">I</span> <span class="cm-variable" style="color:rgb(0,0,0);">CONTROL</span> [<span class="cm-variable" style="color:rgb(0,0,0);">initandlisten</span>] </span> <span><span class="cm-operator" style="color:rgb(152,26,26);">></span> </span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>然后在输入</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span></span> <span>show dbs</span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>就能看见目前我们的数据库</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span><span class="cm-variable" style="color:rgb(0,0,0);">show</span> <span class="cm-variable" style="color:rgb(0,0,0);">dbs</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">admin</span>     <span class="cm-number" style="color:rgb(17,102,68);">0.000</span><span class="cm-variable" style="color:rgb(0,0,0);">GB</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">config</span>    <span class="cm-number" style="color:rgb(17,102,68);">0.000</span><span class="cm-variable" style="color:rgb(0,0,0);">GB</span></span> <span><span class="cm-variable" style="color:rgb(0,0,0);">local</span>     <span class="cm-number" style="color:rgb(17,102,68);">0.000</span><span class="cm-variable" style="color:rgb(0,0,0);">GB</span></span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>没有我们就用我们的创建数据库的命令进行创建参考这篇文章:</span><span><span><</span><span class="md-tag" style="text-align:left;color:inherit;"><MongoDB数据的创建和用法></span><span>></span></span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>这些工作都做完了.就来到我们的最后一步.启动我们的爬虫进行爬取.</span></span></p> <pre class="md-fences md-end-block" style="font-family:Consolas, 'Liberation Mono', Courier, monospace;font-size:.9em;text-align:left;background-image:inherit;background-attachment:inherit;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);width:inherit;color:rgb(51,51,51);font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;"><span></span> <span>scrapy crawl douban</span></pre> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><span>最后完成的效果图:</span></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block"><a href="http://img.e-com-net.com/image/info8/33a56f1c91a74d2881781f4953a8abdb.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/33a56f1c91a74d2881781f4953a8abdb.jpg" alt="Scrapy框架的使用_第1张图片" width="650" height="290" style="border:1px solid black;"></a><br></span></p> <p style="width:inherit;color:rgb(51,51,51);font-family:'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);"><span class="md-line md-end-block md-focus"><span class="md-expand">至此250条数据就完美搞定.</span></span></p> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1188486774675054592"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(Python,spider,scrapy)</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1835511912843014144.htm" title="理解Gunicorn:Python WSGI服务器的基石" target="_blank">理解Gunicorn:Python WSGI服务器的基石</a> <span class="text-muted">范范0825</span> <a class="tag" taget="_blank" href="/search/ipython/1.htm">ipython</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a> <div>理解Gunicorn:PythonWSGI服务器的基石介绍Gunicorn,全称GreenUnicorn,是一个为PythonWSGI(WebServerGatewayInterface)应用设计的高效、轻量级HTTP服务器。作为PythonWeb应用部署的常用工具,Gunicorn以其高性能和易用性著称。本文将介绍Gunicorn的基本概念、安装和配置,帮助初学者快速上手。1.什么是Gunico</div> </li> <li><a href="/article/1835506869838376960.htm" title="Python数据分析与可视化实战指南" target="_blank">Python数据分析与可视化实战指南</a> <span class="text-muted">William数据分析</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE/1.htm">数据</a> <div>在数据驱动的时代,Python因其简洁的语法、强大的库生态系统以及活跃的社区,成为了数据分析与可视化的首选语言。本文将通过一个详细的案例,带领大家学习如何使用Python进行数据分析,并通过可视化来直观呈现分析结果。一、环境准备1.1安装必要库在开始数据分析和可视化之前,我们需要安装一些常用的库。主要包括pandas、numpy、matplotlib和seaborn等。这些库分别用于数据处理、数学</div> </li> <li><a href="/article/1835505858939809792.htm" title="python os.environ" target="_blank">python os.environ</a> <span class="text-muted">江湖偌大</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/1.htm">深度学习</a> <div>os.environ['TF_CPP_MIN_LOG_LEVEL']='0'#默认值,输出所有信息os.environ['TF_CPP_MIN_LOG_LEVEL']='1'#屏蔽通知信息(INFO)os.environ['TF_CPP_MIN_LOG_LEVEL']='2'#屏蔽通知信息和警告信息(INFO\WARNING)os.environ['TF_CPP_MIN_LOG_LEVEL']='</div> </li> <li><a href="/article/1835505606245576704.htm" title="Python中os.environ基本介绍及使用方法" target="_blank">Python中os.environ基本介绍及使用方法</a> <span class="text-muted">鹤冲天Pro</span> <a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>文章目录python中os.environos.environ简介os.environ进行环境变量的增删改查python中os.environ的使用详解1.简介2.key字段详解2.1常见key字段3.os.environ.get()用法4.环境变量的增删改查和判断是否存在4.1新增环境变量4.2更新环境变量4.3获取环境变量4.4删除环境变量4.5判断环境变量是否存在python中os.envi</div> </li> <li><a href="/article/1835505226933694464.htm" title="Pyecharts数据可视化大屏:打造沉浸式数据分析体验" target="_blank">Pyecharts数据可视化大屏:打造沉浸式数据分析体验</a> <span class="text-muted">我的运维人生</span> <a class="tag" taget="_blank" href="/search/%E4%BF%A1%E6%81%AF%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">信息可视化</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98/1.htm">数据挖掘</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4%E5%BC%80%E5%8F%91/1.htm">运维开发</a><a class="tag" taget="_blank" href="/search/%E6%8A%80%E6%9C%AF%E5%85%B1%E4%BA%AB/1.htm">技术共享</a> <div>Pyecharts数据可视化大屏:打造沉浸式数据分析体验在当今这个数据驱动的时代,如何将海量数据以直观、生动的方式展现出来,成为了数据分析师和企业决策者关注的焦点。Pyecharts,作为一款基于Python的开源数据可视化库,凭借其丰富的图表类型、灵活的配置选项以及高度的定制化能力,成为了构建数据可视化大屏的理想选择。本文将深入探讨如何利用Pyecharts打造数据可视化大屏,并通过实际代码案例</div> </li> <li><a href="/article/1835504217729626112.htm" title="Python教程:一文了解使用Python处理XPath" target="_blank">Python教程:一文了解使用Python处理XPath</a> <span class="text-muted">旦莫</span> <a class="tag" taget="_blank" href="/search/Python%E8%BF%9B%E9%98%B6/1.htm">Python进阶</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>目录1.环境准备1.1安装lxml1.2验证安装2.XPath基础2.1什么是XPath?2.2XPath语法2.3示例XML文档3.使用lxml解析XML3.1解析XML文档3.2查看解析结果4.XPath查询4.1基本路径查询4.2使用属性查询4.3查询多个节点5.XPath的高级用法5.1使用逻辑运算符5.2使用函数6.实战案例6.1从网页抓取数据6.1.1安装Requests库6.1.2代</div> </li> <li><a href="/article/1835503965563875328.htm" title="python os.environ_python os.environ 读取和设置环境变量" target="_blank">python os.environ_python os.environ 读取和设置环境变量</a> <span class="text-muted">weixin_39605414</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/os.environ/1.htm">os.environ</a> <div>>>>importos>>>os.environ.keys()['LC_NUMERIC','GOPATH','GOROOT','GOBIN','LESSOPEN','SSH_CLIENT','LOGNAME','USER','HOME','LC_PAPER','PATH','DISPLAY','LANG','TERM','SHELL','J2REDIR','LC_MONETARY','QT_QPA</div> </li> <li><a href="/article/1835497664922349568.htm" title="使用Faiss进行高效相似度搜索" target="_blank">使用Faiss进行高效相似度搜索</a> <span class="text-muted">llzwxh888</span> <a class="tag" taget="_blank" href="/search/faiss/1.htm">faiss</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>在现代AI应用中,快速和高效的相似度搜索是至关重要的。Faiss(FacebookAISimilaritySearch)是一个专门用于快速相似度搜索和聚类的库,特别适用于高维向量。本文将介绍如何使用Faiss来进行相似度搜索,并结合Python代码演示其基本用法。什么是Faiss?Faiss是一个由FacebookAIResearch团队开发的开源库,主要用于高维向量的相似性搜索和聚类。Faiss</div> </li> <li><a href="/article/1835497665853485056.htm" title="python是什么意思中文-在python中%是什么意思" target="_blank">python是什么意思中文-在python中%是什么意思</a> <span class="text-muted">编程大乐趣</span> <div>Python中%有两种:1、数值运算:%代表取模,返回除法的余数。如:>>>7%212、%操作符(字符串格式化,stringformatting),说明如下:%[(name)][flags][width].[precision]typecode(name)为命名flags可以有+,-,''或0。+表示右对齐。-表示左对齐。''为一个空格,表示在正数的左侧填充一个空格,从而与负数对齐。0表示使用0填</div> </li> <li><a href="/article/1835495644123459584.htm" title="Day1笔记-Python简介&标识符和关键字&输入输出" target="_blank">Day1笔记-Python简介&标识符和关键字&输入输出</a> <span class="text-muted">~在杰难逃~</span> <a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98/1.htm">数据挖掘</a> <div>大家好,从今天开始呢,杰哥开展一个新的专栏,当然,数据分析部分也会不定时更新的,这个新的专栏主要是讲解一些Python的基础语法和知识,帮助0基础的小伙伴入门和学习Python,感兴趣的小伙伴可以开始认真学习啦!一、Python简介【了解】1.计算机工作原理编程语言就是用来定义计算机程序的形式语言。我们通过编程语言来编写程序代码,再通过语言处理程序执行向计算机发送指令,让计算机完成对应的工作,编程</div> </li> <li><a href="/article/1835495517774245888.htm" title="python八股文面试题分享及解析(1)" target="_blank">python八股文面试题分享及解析(1)</a> <span class="text-muted">Shawn________</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>#1.'''a=1b=2不用中间变量交换a和b'''#1.a=1b=2a,b=b,aprint(a)print(b)结果:21#2.ll=[]foriinrange(3):ll.append({'num':i})print(11)结果:#[{'num':0},{'num':1},{'num':2}]#3.kk=[]a={'num':0}foriinrange(3):#0,12#可变类型,不仅仅改变</div> </li> <li><a href="/article/1835493753557708800.htm" title="每日算法&面试题,大厂特训二十八天——第二十天(树)" target="_blank">每日算法&面试题,大厂特训二十八天——第二十天(树)</a> <span class="text-muted">肥学</span> <a class="tag" taget="_blank" href="/search/%E2%9A%A1%E7%AE%97%E6%B3%95%E9%A2%98%E2%9A%A1%E9%9D%A2%E8%AF%95%E9%A2%98%E6%AF%8F%E6%97%A5%E7%B2%BE%E8%BF%9B/1.htm">⚡算法题⚡面试题每日精进</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a> <div>目录标题导读算法特训二十八天面试题点击直接资料领取导读肥友们为了更好的去帮助新同学适应算法和面试题,最近我们开始进行专项突击一步一步来。上一期我们完成了动态规划二十一天现在我们进行下一项对各类算法进行二十八天的一个小总结。还在等什么快来一起肥学进行二十八天挑战吧!!特别介绍小白练手专栏,适合刚入手的新人欢迎订阅编程小白进阶python有趣练手项目里面包括了像《机器人尬聊》《恶搞程序》这样的有趣文章</div> </li> <li><a href="/article/1835493626688401408.htm" title="Python快速入门 —— 第三节:类与对象" target="_blank">Python快速入门 —— 第三节:类与对象</a> <span class="text-muted">孤华暗香</span> <a class="tag" taget="_blank" href="/search/Python%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/1.htm">Python快速入门</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>第三节:类与对象目标:了解面向对象编程的基础概念,并学会如何定义类和创建对象。内容:类与对象:定义类:class关键字。类的构造函数:__init__()。类的属性和方法。对象的创建与使用。示例:classStudent:def__init__(self,name,age,major):self.name&#</div> </li> <li><a href="/article/1835492869062881280.htm" title="pyecharts——绘制柱形图折线图" target="_blank">pyecharts——绘制柱形图折线图</a> <span class="text-muted">2224070247</span> <a class="tag" taget="_blank" href="/search/%E4%BF%A1%E6%81%AF%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">信息可视化</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">数据可视化</a> <div>一、pyecharts概述自2013年6月百度EFE(ExcellentFrontEnd)数据可视化团队研发的ECharts1.0发布到GitHub网站以来,ECharts一直备受业界权威的关注并获得广泛好评,成为目前成熟且流行的数据可视化图表工具,被应用到诸多数据可视化的开发领域。Python作为数据分析领域最受欢迎的语言,也加入ECharts的使用行列,并研发出方便Python开发者使用的数据</div> </li> <li><a href="/article/1835491859351302144.htm" title="Python 实现图片裁剪(附代码) | Python工具" target="_blank">Python 实现图片裁剪(附代码) | Python工具</a> <span class="text-muted">剑客阿良_ALiang</span> <div>前言本文提供将图片按照自定义尺寸进行裁剪的工具方法,一如既往的实用主义。环境依赖ffmpeg环境安装,可以参考我的另一篇文章:windowsffmpeg安装部署_阿良的博客-CSDN博客本文主要使用到的不是ffmpeg,而是ffprobe也在上面这篇文章中的zip包中。ffmpy安装:pipinstallffmpy-ihttps://pypi.douban.com/simple代码不废话了,上代码</div> </li> <li><a href="/article/1835491353451130880.htm" title="【华为OD技术面试真题 - 技术面】- python八股文真题题库(4)" target="_blank">【华为OD技术面试真题 - 技术面】- python八股文真题题库(4)</a> <span class="text-muted">算法大师</span> <a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>华为OD面试真题精选专栏:华为OD面试真题精选目录:2024华为OD面试手撕代码真题目录以及八股文真题目录文章目录华为OD面试真题精选**1.Python中的`with`**用途和功能自动资源管理示例:文件操作上下文管理协议示例代码工作流程解析优点2.\_\_new\_\_和**\_\_init\_\_**区别__new____init__区别总结3.**切片(Slicing)操作**基本切片语法</div> </li> <li><a href="/article/1835490974911000576.htm" title="python os 环境变量" target="_blank">python os 环境变量</a> <span class="text-muted">CV矿工</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/numpy/1.htm">numpy</a> <div>环境变量:环境变量是程序和操作系统之间的通信方式。有些字符不宜明文写进代码里,比如数据库密码,个人账户密码,如果写进自己本机的环境变量里,程序用的时候通过os.environ.get()取出来就行了。os.environ是一个环境变量的字典。环境变量的相关操作importos"""设置/修改环境变量:os.environ[‘环境变量名称’]=‘环境变量值’#其中key和value均为string类</div> </li> <li><a href="/article/1835490218845761536.htm" title="Python爬虫解析工具之xpath使用详解" target="_blank">Python爬虫解析工具之xpath使用详解</a> <span class="text-muted">eqa11</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB/1.htm">爬虫</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>文章目录Python爬虫解析工具之xpath使用详解一、引言二、环境准备1、插件安装2、依赖库安装三、xpath语法详解1、路径表达式2、通配符3、谓语4、常用函数四、xpath在Python代码中的使用1、文档树的创建2、使用xpath表达式3、获取元素内容和属性五、总结Python爬虫解析工具之xpath使用详解一、引言在Python爬虫开发中,数据提取是一个至关重要的环节。xpath作为一门</div> </li> <li><a href="/article/1835483915071090688.htm" title="【华为OD技术面试真题 - 技术面】- python八股文真题题库(1)" target="_blank">【华为OD技术面试真题 - 技术面】- python八股文真题题库(1)</a> <span class="text-muted">算法大师</span> <a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>华为OD面试真题精选专栏:华为OD面试真题精选目录:2024华为OD面试手撕代码真题目录以及八股文真题目录文章目录华为OD面试真题精选1.数据预处理流程数据预处理的主要步骤工具和库2.介绍线性回归、逻辑回归模型线性回归(LinearRegression)模型形式:关键点:逻辑回归(LogisticRegression)模型形式:关键点:参数估计与评估:3.python浅拷贝及深拷贝浅拷贝(Shal</div> </li> <li><a href="/article/1835483159630802944.htm" title="nosql数据库技术与应用知识点" target="_blank">nosql数据库技术与应用知识点</a> <span class="text-muted">皆过客,揽星河</span> <a class="tag" taget="_blank" href="/search/NoSQL/1.htm">NoSQL</a><a class="tag" taget="_blank" href="/search/nosql/1.htm">nosql</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a><a class="tag" taget="_blank" href="/search/%E9%9D%9E%E5%85%B3%E7%B3%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">非关系型数据库</a> <div>Nosql知识回顾大数据处理流程数据采集(flume、爬虫、传感器)数据存储(本门课程NoSQL所处的阶段)Hdfs、MongoDB、HBase等数据清洗(入仓)Hive等数据处理、分析(Spark、Flink等)数据可视化数据挖掘、机器学习应用(Python、SparkMLlib等)大数据时代存储的挑战(三高)高并发(同一时间很多人访问)高扩展(要求随时根据需求扩展存储)高效率(要求读写速度快)</div> </li> <li><a href="/article/1835481269690003456.htm" title="《Python数据分析实战终极指南》" target="_blank">《Python数据分析实战终极指南》</a> <span class="text-muted">xjt921122</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>对于分析师来说,大家在学习Python数据分析的路上,多多少少都遇到过很多大坑**,有关于技能和思维的**:Excel已经没办法处理现有的数据量了,应该学Python吗?找了一大堆Python和Pandas的资料来学习,为什么自己动手就懵了?跟着比赛类公开数据分析案例练了很久,为什么当自己面对数据需求还是只会数据处理而没有分析思路?学了对比、细分、聚类分析,也会用PEST、波特五力这类分析法,为啥</div> </li> <li><a href="/article/1835477362700021760.htm" title="Python中深拷贝与浅拷贝的区别" target="_blank">Python中深拷贝与浅拷贝的区别</a> <span class="text-muted">yuxiaoyu.</span> <div>转自:http://blog.csdn.net/u014745194/article/details/70271868定义:在Python中对象的赋值其实就是对象的引用。当创建一个对象,把它赋值给另一个变量的时候,python并没有拷贝这个对象,只是拷贝了这个对象的引用而已。浅拷贝:拷贝了最外围的对象本身,内部的元素都只是拷贝了一个引用而已。也就是,把对象复制一遍,但是该对象中引用的其他对象我不复</div> </li> <li><a href="/article/1835476983614631936.htm" title="Python开发常用的三方模块如下:" target="_blank">Python开发常用的三方模块如下:</a> <span class="text-muted">换个网名有点难</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>Python是一门功能强大的编程语言,拥有丰富的第三方库,这些库为开发者提供了极大的便利。以下是100个常用的Python库,涵盖了多个领域:1、NumPy,用于科学计算的基础库。2、Pandas,提供数据结构和数据分析工具。3、Matplotlib,一个绘图库。4、Scikit-learn,机器学习库。5、SciPy,用于数学、科学和工程的库。6、TensorFlow,由Google开发的开源机</div> </li> <li><a href="/article/1835473704432267264.htm" title="Python编译器" target="_blank">Python编译器</a> <span class="text-muted">鹿鹿~</span> <a class="tag" taget="_blank" href="/search/Python%E7%BC%96%E8%AF%91%E5%99%A8/1.htm">Python编译器</a><a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>嘿嘿嘿我又来了啊有些小盆友可能不知道Python其实是有编译器的,也就是PyCharm。你们可能会问到这个是干嘛的又不可以吃也不可以穿好像没有什么用,其实你还说对了这个还真的不可以吃也不可以穿,但是它用来干嘛的呢。用来编译你所打出的代码进行运行(可能这里说的有点不对但是只是个人认为)现在我们来说说PyCharm是用来干嘛的。PyCharm是一种PythonIDE,带有一整套可以帮助用户在使用Pyt</div> </li> <li><a href="/article/1835471437754888192.htm" title="一文掌握python面向对象魔术方法(二)" target="_blank">一文掌握python面向对象魔术方法(二)</a> <span class="text-muted">程序员neil</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>接上篇:一文掌握python面向对象魔术方法(一)-CSDN博客目录六、迭代和序列化:1、__iter__(self):定义迭代器,使得类可以被for循环迭代。2、__getitem__(self,key):定义索引操作,如obj[key]。3、__setitem__(self,key,value):定义赋值操作,如obj[key]=value。4、__delitem__(self,key):定义</div> </li> <li><a href="/article/1835471185589137408.htm" title="一文掌握python常用的list(列表)操作" target="_blank">一文掌握python常用的list(列表)操作</a> <span class="text-muted">程序员neil</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>目录一、创建列表1.直接创建列表:2.使用list()构造器3.使用列表推导式4.创建空列表二、访问列表元素1.列表支持通过索引访问元素,索引从0开始:2.还可以使用切片操作访问列表的一部分:三、修改列表元素四、添加元素1.append():在末尾添加元素2.insert():在指定位置插入元素五、删除元素1.del:删除指定位置的元素2.remove():删除指定值的第一个匹配项3.pop():</div> </li> <li><a href="/article/1835469798838988800.htm" title="Python实现简单的机器学习算法" target="_blank">Python实现简单的机器学习算法</a> <span class="text-muted">master_chenchengg</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%8A%9E%E5%85%AC%E6%95%88%E7%8E%87/1.htm">办公效率</a><a class="tag" taget="_blank" href="/search/python%E5%BC%80%E5%8F%91/1.htm">python开发</a><a class="tag" taget="_blank" href="/search/IT/1.htm">IT</a> <div>Python实现简单的机器学习算法开篇:初探机器学习的奇妙之旅搭建环境:一切从安装开始必备工具箱第一步:安装Anaconda和JupyterNotebook小贴士:如何配置Python环境变量算法初体验:从零开始的Python机器学习线性回归:让数据说话数据准备:从哪里找数据编码实战:Python实现线性回归模型评估:如何判断模型好坏逻辑回归:从分类开始理论入门:什么是逻辑回归代码实现:使用skl</div> </li> <li><a href="/article/1835465134710026240.htm" title="python中的深拷贝与浅拷贝" target="_blank">python中的深拷贝与浅拷贝</a> <span class="text-muted">anshejd70787</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>深拷贝和浅拷贝浅拷贝的时候,修改原来的对象,浅拷贝的对象不会发生改变。1、对象的赋值对象的赋值实际上是对象之间的引用:当创建一个对象,然后将这个对象赋值给另外一个变量的时候,python并没有拷贝这个对象,而只是拷贝了这个对象的引用。当对对象做赋值或者是参数传递或者作为返回值的时候,总是传递原始对象的引用,而不是一个副本。如下所示:>>>aList=["kel","abc",123]>>>bLis</div> </li> <li><a href="/article/1835463874560749568.htm" title="用Python实现简单的猜数字游戏" target="_blank">用Python实现简单的猜数字游戏</a> <span class="text-muted">程序媛了了</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%B8%B8%E6%88%8F/1.htm">游戏</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>猜数字游戏代码:importrandomdefpythonit():a=random.randint(1,100)n=int(input("输入你猜想的数字:"))whilen!=a:ifn>a:print("很遗憾,猜大了")n=int(input("请再次输入你猜想的数字:"))elifna::如果玩家猜的数字n大于随机数字a,则输出"很遗憾,猜大了",并提示玩家再次输入。elifn<a::如</div> </li> <li><a href="/article/1835463875160535040.htm" title="用Python实现读取统计单词个数" target="_blank">用Python实现读取统计单词个数</a> <span class="text-muted">程序媛了了</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%B8%B8%E6%88%8F/1.htm">游戏</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>完整实例代码:fromcollectionsimportCounterdefpythonit():danci={}withopen("pythonit.txt","r",encoding="utf-8")asf:foriinf:words=i.strip().split()forwordinwords:ifwordnotindanci:danci[word]=1else:danci[word]+=</div> </li> <li><a href="/article/12.htm" title="eclipse maven" target="_blank">eclipse maven</a> <span class="text-muted">IXHONG</span> <a class="tag" taget="_blank" href="/search/eclipse/1.htm">eclipse</a> <div>eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.   可以设一个环境变量M2_HOME指</div> </li> <li><a href="/article/139.htm" title="timer cancel方法的一个小实例" target="_blank">timer cancel方法的一个小实例</a> <span class="text-muted">alleni123</span> <a class="tag" taget="_blank" href="/search/%E5%A4%9A%E7%BA%BF%E7%A8%8B/1.htm">多线程</a><a class="tag" taget="_blank" href="/search/timer/1.htm">timer</a> <div>package com.lj.timer; import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class MyTimer extends TimerTask { private int a; private Timer timer; pub</div> </li> <li><a href="/article/266.htm" title="MySQL数据库在Linux下的安装" target="_blank">MySQL数据库在Linux下的安装</a> <span class="text-muted">ducklsl</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a> <div>1.建好一个专门放置MySQL的目录 /mysql/db数据库目录 /mysql/data数据库数据文件目录 2.配置用户,添加专门的MySQL管理用户 >groupadd mysql ----添加用户组 >useradd -g mysql mysql ----在mysql用户组中添加一个mysql用户 3.配置,生成并安装MySQL >cmake -D</div> </li> <li><a href="/article/393.htm" title="spring------>>cvc-elt.1: Cannot find the declaration of element" target="_blank">spring------>>cvc-elt.1: Cannot find the declaration of element</a> <span class="text-muted">Array_06</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/bean/1.htm">bean</a> <div>将-------- <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3</div> </li> <li><a href="/article/520.htm" title="maven发布第三方jar的一些问题" target="_blank">maven发布第三方jar的一些问题</a> <span class="text-muted">cugfy</span> <a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a> <div>maven中发布 第三方jar到nexus仓库使用的是 deploy:deploy-file命令 有许多参数,具体可查看 http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html 以下是一个例子: mvn  deploy:deploy-file -DgroupId=xpp3 </div> </li> <li><a href="/article/647.htm" title="MYSQL下载及安装" target="_blank">MYSQL下载及安装</a> <span class="text-muted">357029540</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a> <div>    好久没有去安装过MYSQL,今天自己在安装完MYSQL过后用navicat for mysql去厕测试链接的时候出现了10061的问题,因为的的MYSQL是最新版本为5.6.24,所以下载的文件夹里没有my.ini文件,所以在网上找了很多方法还是没有找到怎么解决问题,最后看到了一篇百度经验里有这个的介绍,按照其步骤也完成了安装,在这里给大家分享下这个链接的地址</div> </li> <li><a href="/article/774.htm" title="ios TableView cell的布局" target="_blank">ios TableView cell的布局</a> <span class="text-muted">张亚雄</span> <a class="tag" taget="_blank" href="/search/tableview/1.htm">tableview</a> <div>  cell.imageView.image = [UIImage imageNamed:[imageArray objectAtIndex:[indexPath row]]];           CGSize itemSize = CGSizeMake(60, 50);   &nbs</div> </li> <li><a href="/article/901.htm" title="Java编码转义" target="_blank">Java编码转义</a> <span class="text-muted">adminjun</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A0%81%E8%BD%AC%E4%B9%89/1.htm">编码转义</a> <div> import java.io.UnsupportedEncodingException; /** * 转换字符串的编码 */ public class ChangeCharset { /** 7位ASCII字符,也叫作ISO646-US、Unicode字符集的基本拉丁块 */ public static final Strin</div> </li> <li><a href="/article/1028.htm" title="Tomcat 配置和spring" target="_blank">Tomcat 配置和spring</a> <span class="text-muted">aijuans</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a> <div>简介 Tomcat启动时,先找系统变量CATALINA_BASE,如果没有,则找CATALINA_HOME。然后找这个变量所指的目录下的conf文件夹,从中读取配置文件。最重要的配置文件:server.xml 。要配置tomcat,基本上了解server.xml,context.xml和web.xml。 Server.xml --  tomcat主</div> </li> <li><a href="/article/1155.htm" title="Java打印当前目录下的所有子目录和文件" target="_blank">Java打印当前目录下的所有子目录和文件</a> <span class="text-muted">ayaoxinchao</span> <a class="tag" taget="_blank" href="/search/%E9%80%92%E5%BD%92/1.htm">递归</a><a class="tag" taget="_blank" href="/search/File/1.htm">File</a> <div>其实这个没啥技术含量,大湿们不要操笑哦,只是做一个简单的记录,简单用了一下递归算法。   import java.io.File; /** * @author Perlin * @date 2014-6-30 */ public class PrintDirectory { public static void printDirectory(File f</div> </li> <li><a href="/article/1282.htm" title="linux安装mysql出现libs报冲突解决" target="_blank">linux安装mysql出现libs报冲突解决</a> <span class="text-muted">BigBird2012</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>linux安装mysql出现libs报冲突解决 安装mysql出现 file /usr/share/mysql/ukrainian/errmsg.sys from install of MySQL-server-5.5.33-1.linux2.6.i386 conflicts with file from package mysql-libs-5.1.61-4.el6.i686  </div> </li> <li><a href="/article/1409.htm" title="jedis连接池使用实例" target="_blank">jedis连接池使用实例</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/redis/1.htm">redis</a><a class="tag" taget="_blank" href="/search/jedis%E8%BF%9E%E6%8E%A5%E6%B1%A0/1.htm">jedis连接池</a><a class="tag" taget="_blank" href="/search/jedis/1.htm">jedis</a> <div>实例代码: package com.bijian.study; import java.util.ArrayList; import java.util.List; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoo</div> </li> <li><a href="/article/1536.htm" title="关于朋友" target="_blank">关于朋友</a> <span class="text-muted">bingyingao</span> <a class="tag" taget="_blank" href="/search/%E6%9C%8B%E5%8F%8B/1.htm">朋友</a><a class="tag" taget="_blank" href="/search/%E5%85%B4%E8%B6%A3%E7%88%B1%E5%A5%BD/1.htm">兴趣爱好</a><a class="tag" taget="_blank" href="/search/%E7%BB%B4%E6%8C%81/1.htm">维持</a> <div>  成为朋友的必要条件:    志相同,道不合,可以成为朋友。譬如马云、周星驰一个是商人,一个是影星,可谓道不同,但都很有梦想,都要在各自领域里做到最好,当他们遇到一起,互相欣赏,可以畅谈两个小时。     志不同,道相合,也可以成为朋友。譬如有时候看到两个一个成绩很好每次考试争做第一,一个成绩很差的同学是好朋友。他们志向不相同,但他</div> </li> <li><a href="/article/1663.htm" title="【Spark七十九】Spark RDD API一" target="_blank">【Spark七十九】Spark RDD API一</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/spark/1.htm">spark</a> <div>aggregate package spark.examples.rddapi import org.apache.spark.{SparkConf, SparkContext} //测试RDD的aggregate方法 object AggregateTest { def main(args: Array[String]) { val conf = new Spar</div> </li> <li><a href="/article/1790.htm" title="ktap 0.1 released" target="_blank">ktap 0.1 released</a> <span class="text-muted">bookjovi</span> <a class="tag" taget="_blank" href="/search/kernel/1.htm">kernel</a><a class="tag" taget="_blank" href="/search/tracing/1.htm">tracing</a> <div>Dear, I'm pleased to announce that ktap release v0.1, this is the first official release of ktap project, it is expected that this release is not fully functional or very stable and we welcome bu</div> </li> <li><a href="/article/1917.htm" title="能保存Properties文件注释的Properties工具类" target="_blank">能保存Properties文件注释的Properties工具类</a> <span class="text-muted">BrokenDreams</span> <a class="tag" taget="_blank" href="/search/properties/1.htm">properties</a> <div>        今天遇到一个小需求:由于java.util.Properties读取属性文件时会忽略注释,当写回去的时候,注释都没了。恰好一个项目中的配置文件会在部署后被某个Java程序修改一下,但修改了之后注释全没了,可能会给以后的参数调整带来困难。所以要解决这个问题。     &nb</div> </li> <li><a href="/article/2044.htm" title="读《研磨设计模式》-代码笔记-外观模式-Facade" target="_blank">读《研磨设计模式》-代码笔记-外观模式-Facade</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a> <div>声明: 本文只为方便我个人查阅和理解,详细的分析以及源代码请移步 原作者的博客http://chjavach.iteye.com/ /* * 百度百科的定义: * Facade(外观)模式为子系统中的各类(或结构与方法)提供一个简明一致的界面, * 隐藏子系统的复杂性,使子系统更加容易使用。他是为子系统中的一组接口所提供的一个一致的界面 * * 可简单地</div> </li> <li><a href="/article/2171.htm" title="After Effects教程收集" target="_blank">After Effects教程收集</a> <span class="text-muted">cherishLC</span> <a class="tag" taget="_blank" href="/search/After+Effects/1.htm">After Effects</a> <div>1、中文入门 http://study.163.com/course/courseMain.htm?courseId=730009 2、videocopilot英文入门教程(中文字幕) http://www.youku.com/playlist_show/id_17893193.html 英文原址: http://www.videocopilot.net/basic/ 素</div> </li> <li><a href="/article/2298.htm" title="Linux Apache 安装过程" target="_blank">Linux Apache 安装过程</a> <span class="text-muted">crabdave</span> <a class="tag" taget="_blank" href="/search/apache/1.htm">apache</a> <div>Linux Apache 安装过程   下载新版本: apr-1.4.2.tar.gz(下载网站:http://apr.apache.org/download.cgi) apr-util-1.3.9.tar.gz(下载网站:http://apr.apache.org/download.cgi) httpd-2.2.15.tar.gz(下载网站:http://httpd.apac</div> </li> <li><a href="/article/2425.htm" title="Shell学习 之 变量赋值和引用" target="_blank">Shell学习 之 变量赋值和引用</a> <span class="text-muted">daizj</span> <a class="tag" taget="_blank" href="/search/shell/1.htm">shell</a><a class="tag" taget="_blank" href="/search/%E5%8F%98%E9%87%8F%E5%BC%95%E7%94%A8/1.htm">变量引用</a><a class="tag" taget="_blank" href="/search/%E8%B5%8B%E5%80%BC/1.htm">赋值</a> <div>本文转自:http://www.cnblogs.com/papam/articles/1548679.html Shell编程中,使用变量无需事先声明,同时变量名的命名须遵循如下规则: 首个字符必须为字母(a-z,A-Z) 中间不能有空格,可以使用下划线(_) 不能使用标点符号 不能使用bash里的关键字(可用help命令查看保留关键字) 需要给变量赋值时,可以这么写: </div> </li> <li><a href="/article/2552.htm" title="Java SE 第一讲(Java SE入门、JDK的下载与安装、第一个Java程序、Java程序的编译与执行)" target="_blank">Java SE 第一讲(Java SE入门、JDK的下载与安装、第一个Java程序、Java程序的编译与执行)</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/jdk/1.htm">jdk</a> <div>Java SE 第一讲: Java SE:Java Standard Edition Java ME: Java Mobile Edition Java EE:Java Enterprise Edition Java是由Sun公司推出的(今年初被Oracle公司收购)。 收购价格:74亿美金 J2SE、J2ME、J2EE JDK:Java Development </div> </li> <li><a href="/article/2679.htm" title="YII给用户登录加上验证码" target="_blank">YII给用户登录加上验证码</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/yii/1.htm">yii</a> <div>1、在SiteController中添加如下代码: /** * Declares class-based actions. */ public function actions() { return array( // captcha action renders the CAPTCHA image displ</div> </li> <li><a href="/article/2806.htm" title="Lucene使用说明" target="_blank">Lucene使用说明</a> <span class="text-muted">dyy_gusi</span> <a class="tag" taget="_blank" href="/search/Lucene/1.htm">Lucene</a><a class="tag" taget="_blank" href="/search/search/1.htm">search</a><a class="tag" taget="_blank" href="/search/%E5%88%86%E8%AF%8D%E5%99%A8/1.htm">分词器</a> <div>Lucene使用说明 1、lucene简介 1.1、什么是lucene     Lucene是一个全文搜索框架,而不是应用产品。因此它并不像baidu或者googleDesktop那种拿来就能用,它只是提供了一种工具让你能实现这些产品和功能。 1.2、lucene能做什么     要回答这个问题,先要了解lucene的本质。实际</div> </li> <li><a href="/article/2933.htm" title="学习编程并不难,做到以下几点即可!" target="_blank">学习编程并不难,做到以下几点即可!</a> <span class="text-muted">gcq511120594</span> <a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B/1.htm">编程</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a> <div>不论你是想自己设计游戏,还是开发iPhone或安卓手机上的应用,还是仅仅为了娱乐,学习编程语言都是一条必经之路。编程语言种类繁多,用途各 异,然而一旦掌握其中之一,其他的也就迎刃而解。作为初学者,你可能要先从Java或HTML开始学,一旦掌握了一门编程语言,你就发挥无穷的想象,开发 各种神奇的软件啦。 1、确定目标 学习编程语言既充满乐趣,又充满挑战。有些花费多年时间学习一门编程语言的大学生到</div> </li> <li><a href="/article/3060.htm" title="Java面试十问之三:Java与C++内存回收机制的差别" target="_blank">Java面试十问之三:Java与C++内存回收机制的差别</a> <span class="text-muted">HNUlanwei</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/C%2B%2B/1.htm">C++</a><a class="tag" taget="_blank" href="/search/finalize%28%29/1.htm">finalize()</a><a class="tag" taget="_blank" href="/search/%E5%A0%86%E6%A0%88/1.htm">堆栈</a><a class="tag" taget="_blank" href="/search/%E5%86%85%E5%AD%98%E5%9B%9E%E6%94%B6/1.htm">内存回收</a> <div>大家知道, Java 除了那 8 种基本类型以外,其他都是对象类型(又称为引用类型)的数据。 JVM 会把程序创建的对象存放在堆空间中,那什么又是堆空间呢?其实,堆( Heap)是一个运行时的数据存储区,从它可以分配大小各异的空间。一般,运行时的数据存储区有堆( Heap)和堆栈( Stack),所以要先看它们里面可以分配哪些类型的对象实体,然后才知道如何均衡使用这两种存储区。一般来说,栈中存放的</div> </li> <li><a href="/article/3187.htm" title="第二章 Nginx+Lua开发入门" target="_blank">第二章 Nginx+Lua开发入门</a> <span class="text-muted">jinnianshilongnian</span> <a class="tag" taget="_blank" href="/search/nginx/1.htm">nginx</a><a class="tag" taget="_blank" href="/search/lua/1.htm">lua</a> <div>Nginx入门 本文目的是学习Nginx+Lua开发,对于Nginx基本知识可以参考如下文章: nginx启动、关闭、重启 http://www.cnblogs.com/derekchen/archive/2011/02/17/1957209.html agentzh 的 Nginx 教程 http://openresty.org/download/agentzh-nginx-tutor</div> </li> <li><a href="/article/3314.htm" title="MongoDB windows安装 基本命令" target="_blank">MongoDB windows安装 基本命令</a> <span class="text-muted">liyonghui160com</span> <div>  windows安装    安装目录:   D:\MongoDB\   新建目录   D:\MongoDB\data\db   4.启动进城:   cd D:\MongoDB\bin   mongod -dbpath D:\MongoDB\data\db   &n</div> </li> <li><a href="/article/3441.htm" title="Linux下通过源码编译安装程序" target="_blank">Linux下通过源码编译安装程序</a> <span class="text-muted">pda158</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>一、程序的组成部分   Linux下程序大都是由以下几部分组成:   二进制文件:也就是可以运行的程序文件   库文件:就是通常我们见到的lib目录下的文件   配置文件:这个不必多说,都知道   帮助文档:通常是我们在linux下用man命令查看的命令的文档    二、linux下程序的存放目录   linux程序的存放目录大致有三个地方:   /etc, /b</div> </li> <li><a href="/article/3568.htm" title="WEB开发编程的职业生涯4个阶段" target="_blank">WEB开发编程的职业生涯4个阶段</a> <span class="text-muted">shw3588</span> <a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B/1.htm">编程</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/%E5%B7%A5%E4%BD%9C/1.htm">工作</a><a class="tag" taget="_blank" href="/search/%E7%94%9F%E6%B4%BB/1.htm">生活</a> <div>觉得自己什么都会 2007年从学校毕业,凭借自己原创的ASP毕业设计,以为自己很厉害似的,信心满满去东莞找工作,找面试成功率确实很高,只是工资不高,但依旧无法磨灭那过分的自信,那时候什么考勤系统、什么OA系统、什么ERP,什么都觉得有信心,这样的生涯大概持续了约一年。 根本不是自己想的那样 2008年开始接触很多工作相关的东西,发现太多东西自己根本不会,都需要去学,不管是asp还是js,</div> </li> <li><a href="/article/3695.htm" title="遭遇jsonp同域下变作post请求的坑" target="_blank">遭遇jsonp同域下变作post请求的坑</a> <span class="text-muted">vb2005xu</span> <a class="tag" taget="_blank" href="/search/jsonp/1.htm">jsonp</a><a class="tag" taget="_blank" href="/search/%E5%90%8C%E5%9F%9Fpost/1.htm">同域post</a> <div>今天迁移一个站点时遇到一个坑爹问题,同一个jsonp接口在跨域时都能调用成功,但是在同域下调用虽然成功,但是数据却有问题. 此处贴出我的后端代码片段 $mi_id = htmlspecialchars(trim($_GET['mi_id '])); $mi_cv = htmlspecialchars(trim($_GET['mi_cv ']));  贴出我前端代码片段: $.aj</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>