Python 虚拟环境 python爬虫 scrapy框架

Python虚拟环境安装完成后如何创建项目:

先进入py3scrapy才能创建哦!(我安装的虚拟环境名字是py3scrapy)

Python 虚拟环境 python爬虫 scrapy框架

Python 虚拟环境 python爬虫 scrapy框架
用pycharm打开为
Python 虚拟环境 python爬虫 scrapy框架
Python 虚拟环境 python爬虫 scrapy框架

还需配置环境:

Python 虚拟环境 python爬虫 scrapy框架

在setting中:

# Obey robots.txt rules
# Scrapy框架默认遵守 robots.txt 协议规则,robots规定了一个网站中,哪些地址可以请求,哪些地址不能请求。
# 默认是True,设置为False不遵守这个协议。
ROBOTSTXT_OBEY = False

--------------------------------------------------------------------

爬虫当然不能少了debug:

在baidu.py中打点

然后在根目录下建立debug.py(名字可以随便起)

写入下面是的两行: (baidu是你要进行爬虫的文件)

from scrapy.cmdline import execute
execute(['scrapy', 'crawl', 'baidu'])

如果你嫌麻烦的话,也可以直接在命令行敲 scrapy crawl baidu(其实每次都要敲命令, 有点麻烦,不建议用)

==================================================================

    scrapy 文档   链接:   https://doc.scrapy.org/en/latest/topics/architecture.html

Python 虚拟环境 python爬虫 scrapy框架