一、爬虫–scrapy
1.搭建环境
代码如下(示例):
import scrapy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
2.加载scrapy框架
代码如下(示例):
# terminal 终端实现
cd .. # 跳转到上一层目录
scrapy startproject booktop # 和项目同名的scrapy框架项目
3. setting配置
代码如下(示例):
ROBOTSTXT_OBEY = False # 君子协议 false 不遵守
USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
DOWNLOAD_DELAY = 0.5 # 下载延迟
4.spider编写
代码如下(示例):
# spiders文件夹下创建python文件 ganspider.py
import scrapy
from demo6.items import HouseItem
class GanJiSpider(scrapy.Spider):
name="gan_spider"
allowed_domains=["xiangyang.ganji.com"