当前位置: 首页 > news >正文

企业网站开发的功能wordpress4.9.6 漏洞

企业网站开发的功能,wordpress4.9.6 漏洞,wordpress 启用主题,建网站报价表目录 一、创建一个scrapy项目 二、xpath解析数据 三、通过pipelines管道实现数据保存 四、中间件 一、创建一个scrapy项目 1.创建一个文件夹:C06 在终端输入以下命令: 2.安装scrapy:pip install scrapy 3.来到文件夹下:cd C06 4.创建…

目录

一、创建一个scrapy项目

二、xpath解析数据

三、通过pipelines管道实现数据保存

四、中间件


一、创建一个scrapy项目

1.创建一个文件夹:C06

在终端输入以下命令:

2.安装scrapy:pip install scrapy

3.来到文件夹下:cd C06

4.创建项目:scrapy startproject C06L02(项目名称)

5.切换到C06L02下:cd C06L02/C06L02

    切换到spiders下:cd spiders

6.创建爬虫名称和输入爬取链接:scrapy genspider app https://product.cheshi.com/rank/2-0-0-0-1/

(若是crawlspider爬虫字类实现全站爬取:scrapy genspider -t crawl app http://seller.cheshi.com/jinan/

7.注意看爬虫文件(新生成的app.py)链接是否一致

8.运行爬虫文件:scrapy crawl app       

9.若想要消除日志文件,在settings.py中添加命令:LOG_LEVEL="ERROR" 

    若想要绕过ROBOTS协议,在settings.py中添加命令:ROBOTSTXT_OBEY=False

10.简单的scrapy项目的app.py文件代码如下:

import scrapyclass AppSpider(scrapy.Spider):name = "app"allowed_domains = ["product.cheshi.com"]started_urls = ["http://product.cheshi.com/rank/2-0-0-0-1/"]def parse(self, response):print(response.text)

若是crawlspider爬虫字类实现全站爬取:

import scrapy
from scrapy.linkextractors import linkExtractor
from scrapy.spiders import CrawlSpider, Ruleclass AppSpider(CrawlSpider):name = "app"allowed_domains = ["product.cheshi.com"]started_urls = ["http://product.cheshi.com/jinan"]rules = (Rule(linkExtractor(allow=r"seller.cheshi.com/\d+", deny=r"seller.cheshi.com/\d+/.+"),callback="parse_item",follow=True),)def parse(self, response):print(response.url)

11.user-agent配置:在settings.py文件中将user-agent注释内容展开,添加需要内容

二、xpath解析数据

在app.py文件中修改parse函数

import scrapyclass AppSpider(scrapy.Spider):name = "app"allowed_domains = ["product.cheshi.com"]started_urls = ["http://product.cheshi.com/rank/2-0-0-0-1/"]def parse(self, response):cars = response.xpath('//ul[@class="condition_list_con"]/li')for car in cars:title = car.xpath('./div[@class="m_detail"]//a/text()').get()price = car.xpath('./div[@class="m_detail"]//b/text()').get()

若实现分页爬取则为以下代码

import scrapy
from ..items import C06L10Itemclass AppSpider(scrapy.Spider):name = "app"allowed_domains = ["book.douban.com"]started_urls = ["http://book.douban.com/latest"]def parse(self, response):books = response.xpath('//ul[@class="chart-dashed-list"]/li')for book in books:link = book.xpath('.//h2/a/@href').get()yield scrapy.Request(url=link,callback=self.parse_details)next_url = response.xpath('//*[@id="content"]/div/div[1]/div[4]/span[4]/a/@href').get()if next_url is not None:next_url = response.urljoin(next_url)print(next_url)yield scrapy.Request(url=next_url, callback=self.parse)else:next_url = response.xpath('//*[@id="content"]/div/div[1]/div[4]/span[3]/a/@href').get()next_url = response.urljoin(next_url)print(next_url)yield scrapy.Request(url=next_url, callback=self.parse)def parse_details(self, reponse):item = C06L10Item()item["title"] = response.xpath('//*[id="wrapper"]/h1/span/text()').get()item["publisher"] = response.xpath('//*[id="info"]/a[1]/text()').get()yield item

三、通过pipelines管道实现数据保存

1.在items.py文件中定义数据模型

import scrapyclass C06L04Item(scrapy.Item):title = scrapy.Field()price = scrapy.Field()

2.在app.py文件中添加如下代码

import scrapy
from ..items import C06L04Itemclass AppSpider(scrapy.Spider):name = "app"allowed_domains = ["product.cheshi.com"]started_urls = ["http://product.cheshi.com/rank/2-0-0-0-1/"]def parse(self, response):item = C06L04Item()cars = response.xpath('//ul[@class="condition_list_con"]/li')for car in cars:item["title"] = car.xpath('./div[@class="m_detail"]//a/text()').get()item["price"] = car.xpath('./div[@class="m_detail"]//b/text()').get()yield item

3.在settings.py文件中展开被注释掉的ITEM_PIPELINES,无需修改

4.修改pipelines.py文件代码

from itemadapter import ItemAdapterclass C06L04Pipeline:def process_item(self, item, spider):# print(item["title"],item["price"])return item

若想要保存成文件添加以下代码

from itemadapter import ItemAdapterclass C06L04Pipeline:def __init__(self):self.f = open("data.tet", "w")def process_item(self, item, spider):self.f.write(item["title"]+item["price"]+"\n")return itemdef __del__(self):self.f.close()

存储为mongodb形式为如下代码

from itemadapter import ItemAdapter
import pymongoclass C06L04Pipeline:def __init__(self):self.client = pymongo.MongoClient("mongodb://localhost:27017")self.db = self.client["cheshi"]self.col = self.db["cars"]def process_item(self, item, spider):res = self.col.insert_one(dict(item))print(res.inserted_id)return itemdef __del__(self):print("end")

四、中间件

1.Middleware的应用:随机User-Agent、代理IP、使用Selenium、添加Cookie

2.动态User-Agent

打开settings.py文件中注释掉的DOWNLOADER_MIDDLEWARES

在middlewares.py文件中添加如下代码(只显示修改部分):

import randomdef process_request(self, request, spider):uas = ["User-Agent:Mxxxxxxxxxxxxxxxxxxxxxxxx","User-Agent:Mxxxxxxxxxxxxxxxxxxxxxxxx","User-Agent:Mxxxxxxxxxxxxxxxxxxxxxxxx","User-Agent:Mxxxxxxxxxxxxxxxxxxxxxxxx",]request.headers["User-Agent"] = random.choice(uas)

2.代理IP

具体操作略去,例如:快代理-隧道代理-python-scrapy的文档中心有具体的书写方式

http://www.yayakq.cn/news/231611/

相关文章:

  • 厦门市建设与管理局 官方网站优质网站排名公司
  • 邢台市路桥建设总公司网站云主机和云电脑的区别
  • 江宁网站建设企业域名怎么填写
  • 晋中建设局查合同网站互联网+营销策略怎么写
  • 南京行业网站建设做落地页的网站
  • 网站做的不好会有什么后果扁平化设计网站建设
  • 建设规划展览馆网站的优势网络建设费用
  • 用vue框架做的网站做网站的困难
  • 人员调动在网站上怎么做移动端商城网站开发
  • 方庄网站建设公司涿州市网站建设
  • 企业网站素材图片网站建设 销售 知乎
  • 小企业网站维护一年多少钱有专业做网站优化的吗
  • 网站建设公司专业公司排名扬州网站建设企业
  • 网站正在建设中 html代码商城类网站和o2o网站
  • rails网站开发怎么做竞价托管
  • 老板让我做镜像网站犯法吗长治网站设计制作网站
  • 2019建设银行招聘网站小程序代理注册
  • 广州一起做网站培训网站完整页面
  • 设计方案网站php 图片上载 wordpress
  • 青岛做网站哪家公司好百度快速排名 搜
  • 曲靖做网站建设的公司滁州做网站的公司
  • 2017年做那个网站致富福州外包seo公司
  • 广西网站开发wordpress怎么修改数据库配置文件
  • 长沙网站快速优化排名36氪网站是用什么做的
  • 较成功营销网站的例子北京梦创义网站建设
  • 昆明专业网站排名推广嵩县网站建设
  • 柏乡县建设局网站十堰seo优化分析
  • 国外手机主题网站广州做网站海珠新科
  • 数码网站建设的规模与类别公司网站应达到的功能
  • 支付宝签约网站wordpress网站顶部加横幅