一、爬虫框架Scarpy简介
Scrapy 是一个快速的高层次的屏幕抓取和网页爬虫框架,爬取网站,从网站页面得到结构化的数据,它有着广泛的用途,从数据挖掘到监测和自动测试,Scrapy完全用Python实现,完全开源,代码托管在Github上,可运行在Linux,Windows,Mac和BSD平台上,基于Twisted的异步网络库来处理网络通讯,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网页内容以及各种图片。
二、Scrapy安装指南
我们的安装步骤假设你已经安装一下内容:Python2.7lxmlOpenSSL,我们使用Python的包管理工具pip或者easy_install来安装Scrapy。
pip的安装方式:
easy_install的安装方式:
三、Ubuntu平台上环境配置
1、python的包管理工具
当前的包管理工具链是 easy_install/pip + distribute/setuptools
distutils : Python 自带的基本安装工具, 适用于非常简单的应用场景;
setuptools : 针对 distutils 做了大量扩展, 尤其是加入了包依赖机制. 在部分 Python 子社区已然是事实上的标准;
distribute : 由于 setuptools 开发进度缓慢, 不支持 Python 3, 代码混乱, 一帮程序员另起炉灶, 重构代码, 增加功能, 希望能够取代 setuptools 并被接纳为官方标准库, 他们非常努力, 在很短的时间便让社区接受了 distribute;,setuptools / distribute 都只是扩展了 distutils;
easy_install : setuptools 和 distribute 自带的安装脚本, 也就是一旦 setuptools 或 distribute 安装完毕, easy_install 也便可用. 最大的特点是自动查找 Python 官方维护的包源 PyPI , 安装第三方 Python 包非常方便; 使用:
pip : pip 的目标非常明确 – 取代 easy_install. easy_install 有很多不足: 安装事务是非原子操作, 只支持 svn, 没有提供卸载命令, 安装一系列包时需要写脚本; pip 解决了以上问题, 已俨然成为新的事实标准, virtualenv 与它已经成为一对好搭档;
安装过程:
安装distribute
$ python distribute_setup.py
安装pip:
$ [sudo] python get-pip.py
2、Scrapy的安装
在Windows平台上,可以通过包管理工具或者手动下载各种依赖的二进制包:pywin32,Twisted,zope.interface,lxml,pyOpenSSL,在Ubuntu9.10以后的版本上,官方推荐不用使用Ubuntu提供的python-scrapy包,它们要么太老要么太慢,无法匹配最新的Scrapy,解决方案是,使用官方的Ubuntu Packages,它提供了所有的依赖库,并且对于最新的bug提供持续的更新,稳定性更高,它们持续的从Github仓库(master和stable branches)构建,Scrapy在Ubuntu9.10之后的版本上的安装方法如下:
输入GPG密钥
创建/etc/apt/sources.list.d/scrapy.list 文件
更新包列表,安装scrapy版本,其中VERSION用实际的版本代替,如scrapy-0.22
3、Scrapy依赖库的安装
ubuntu12.04下scrapy依赖库的安装
ImportError: No module named w3lib.http
ImportError: No module named twisted
ImportError: No module named lxml.html
解决:error: libxml/xmlversion.h: No such file or directory
apt-get install python-lxml
解决:ImportError: No module named cssselect
ImportError: No module named OpenSSL
4、定制自己的爬虫开发
切换到文件目录,开启新的工程

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Error loading Pickle file in Python 3.6 environment: ModuleNotFoundError:Nomodulenamed...

How to solve the problem of Jieba word segmentation in scenic spot comment analysis? When we are conducting scenic spot comments and analysis, we often use the jieba word segmentation tool to process the text...

How to use regular expression to match the first closed tag and stop? When dealing with HTML or other markup languages, regular expressions are often required to...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor