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

公司注册信息怎么查做百度seo

公司注册信息怎么查,做百度seo,登不上建设银行网站,网站建设电子书1. 多条管道 多条管道开启(2步): (1)定义管道类 (2)在settings中开启管道 在pipelines中: import urllib.request # 多条管道开启 #(1)定义管道类 #(2)在setti…

1. 多条管道

多条管道开启(2步):
          (1)定义管道类
        (2)在settings中开启管道

在pipelines中:

import urllib.request
# 多条管道开启
#(1)定义管道类
#(2)在settings中开启管道
# "demo_nddw.pipelines.dangdangDownloadPipeline": 301
class dangdangDownloadPipeline:def process_item(self, item, spider):url = 'http:' + item.get('src')filename = './books' + item.get('name') + '.jpg'urllib.request.urlretrieve(url = url, filename=filename())return item

2. 多页下载

        爬取每页的业务逻辑都是一样的,将执行那页的请求再次调用就可以了

# 如果是多页下载的话,必须调整allowed_domains的范围,一般只写域名
allowed_domains = ["category.dangdang.com"]

ddw.py中:

#多页下载
# 爬取每页的业务逻辑是一样的,将执行那页的请求再次调用parse方法就可以了
# https://category.dangdang.com/cp01.27.01.06.00.00.html
# https://category.dangdang.com/pg2-cp01.27.01.06.00.00.html
# https://category.dangdang.com/pg3-cp01.27.01.06.00.00.html
if self.page < 100:self.page = self.page + 1url = self.basic_url + str(self.page) + '-cp01.27.01.06.00.00.html'# 怎么调用parse方法# scrapy.Request就是scrapy的get请求#url就是请求地址、callback就是要执行的函数,不需要()yield scrapy.Request(url = url, callback =self.parse)

3. 电影天堂

        获取:

                第一页的名字

                第二页的图片

涉及到两个页面:使用meta进行传递

pipelines.py

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html# useful for handling different item types with a single interface
from itemadapter import ItemAdapterclass DemoDyttPipeline:#开始def open_spider(self,spider):self.fp = open('dytt.json','w',encoding='utf-8')def process_item(self, item, spider):#中间self.fp.write(str(item))return item#结束def close_spider(self,spider):self.fp.close()

items.py

# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.htmlimport scrapyclass DemoDyttItem(scrapy.Item):# define the fields for your item here like:# name = scrapy.Field()# pass# 名字name = scrapy.Field()# 图片src = scrapy.Field()

dytt.py

import scrapy#导入:从项目的items中导入
from demo_dytt.items import DemoDyttItemclass DyttSpider(scrapy.Spider):name = "dytt"# 调整allowed_domains访问范围:只要域名allowed_domains = ["www.dydytt.net"]start_urls = ["https://www.dydytt.net/html/gndy/dyzz/20250306/65993.html"]def parse(self, response):# pass# print('===========================================================')# 要第一页的图片,和第二页的名字a_list = response.xpath('//div[@class = "co_content8"]//tr[2]//a[2]')for a in a_list:# 获取第一页的name,和要点击的链接name = a.xpath('./text()').extract_first()href  =a.xpath('/@href').extract_first()# 第二页的地址url = 'https://www.dydytt.net' + href# 对第二页链接发起访问# 1)meta字典:传递yield scrapy.Request(url = url,callback=self.parse_second,meta={'name':name})def parse_second(self,response):# 拿不到数据,检查xpath语法是否错误src = response.xpath('//div[@id = "Zoom"]/span/img/@src').extract_first()print(src)#2)接收meta字典meta = response.meta['name']dytt = DemoDyttItem(src = src, name = name)#将dytt返回给管道,需要在settings中开启管道:解除管道注释即是开启管道# ITEM_PIPELINES = {#     "demo_dytt.pipelines.DemoDyttPipeline": 300,# }yield dytt

开启管道:

        在settings.py中解除管道的注释即是开启管道

ITEM_PIPELINES = {"demo_dytt.pipelines.DemoDyttPipeline": 300,
}

4. CrawlSpider

        继承自scrapy.spider

CrawlSpider:what?

        1)定义规则

        2)提取符合规则的链接

        3)解析

链接提取器

        1)导入链接提取器

from scrapy.linkextractors import LinkExtractor

        2)

allow = ()        :正则表达式

restrict_xpaths = ()        :xpath

restrict_css = ()        :不推荐

        scrapy shell 网址,然后进行3)4)的链接提取

导入链接提取器:

        from scrapy.linkextractors import LinkExtractor

        3)allow = ()  语法

link = LinkExtraactor(allow = r' /book/1188_\d+\.html')

        \d表示数字

        +表示1~多

查看:

link.extract_links(response)

        4)restrict_xpaths = ()语法

link1 = LinkExtractor(restrict_xpaths = r' //div[@class = "pages"]/a/@href ')

查看:

link.extract_links(response)

5. CrawlSpider案例

1)创建文件:

        scrapy genspider -t crawl 文件名 网址

2)首页不在提取规则,所以不能提取首页

修改start_urls:

        start_urls = ["https://www.dushu.com/book/1157.html"]

 修改后:

        start_urls = ["https://www.dushu.com/book/1157_1.html"]

http://www.dtcms.com/wzjs/214978.html

相关文章:

  • 大连房地产网站开发seo专员是什么职位
  • 做政府网站的公司推荐湖南seo
  • 个人备案网站可以做淘宝客吗今日重大新闻
  • wordpress做企业官网seo网站有优化培训班吗
  • 老河口城乡建设局网站友情链接百科
  • 网站做推广团队企业网站搭建
  • 免费网站优化排名兰州关键词快速上首页排名
  • 珠海做网站三年多少钱网址查询服务器地址
  • 做网站需要什么配置的笔记本semester是什么意思
  • 怎么对网站上的游记做数据分析搜索引擎优化简称seo
  • 网站开发各年的前景百度宣传推广
  • 免费的图库网站百度官方官网
  • 电子政务门户网站建设的教训百度平台客服联系方式
  • 自己有网站做app吗建站模板哪个好
  • 做画册的国外网站东莞网站排名提升
  • 东莞市网站建设服务机构百度seo系统
  • 网站源代码怎么上传国家高新技术企业名单
  • 马鞍山网站制作seo视频教程我要自学网
  • wordpress搭建网站教程开平网站设计
  • 平台类网站建设价格表政府免费培训面点班
  • 关于网站策划书描述准确的有seo的方法有哪些
  • 如何在相关网站免费做宣传广告网络营销推广的方式
  • 网站制作分工优化网站内容的方法
  • 网站推广 网站百度推广竞价技巧
  • 前端做兼职网站百度app免费下载安装最新版
  • 程序员做网站美工能过关吗seo01网站
  • 如何做网站平台郑州网站优化公司
  • 网站开发建设兼职网络舆情处置的五个步骤
  • 怎么知道公司网站是哪个公司做的2020站群seo系统
  • 网站怎么做自适应图片百度搜索