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

企业网站优化推广怎么做专业的句容网站建设

企业网站优化推广怎么做,专业的句容网站建设,北京城乡建设集团有限公司官网,做建筑的网站目录 一、创建一个scrapy项目 二、xpath解析数据 三、通过pipelines管道实现数据保存 四、中间件 一、创建一个scrapy项目 1.创建一个文件夹#xff1a;C06 在终端输入以下命令#xff1a; 2.安装scrapy:pip install scrapy 3.来到文件夹下#xff1a;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/ 7.注意看爬虫文件新生成的app.py链接是否一致 8.运行爬虫文件scrapy crawl app        9.若想要消除日志文件,在settings.py中添加命令LOG_LEVELERROR  若想要绕过ROBOTS协议,在settings.py中添加命令ROBOTSTXT_OBEYFalse 10.简单的scrapy项目的app.py文件代码如下 import scrapyclass AppSpider(scrapy.Spider):name appallowed_domains [product.cheshi.com]started_urls [http://product.cheshi.com/rank/2-0-0-0-1/]def parse(self, response):print(response.text) 11.user-agent配置在settings.py文件中将user-agent注释内容展开添加需要内容 二、xpath解析数据 在app.py文件中修改parse函数 import scrapyclass AppSpider(scrapy.Spider):name appallowed_domains [product.cheshi.com]started_urls [http://product.cheshi.com/rank/2-0-0-0-1/]def parse(self, response):cars response.xpath(//ul[classcondition_list_con]/li)for car in cars:title car.xpath(./div[classm_detail]//a/text()).get()price car.xpath(./div[classm_detail]//b/text()).get() 三、通过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 appallowed_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[classcondition_list_con]/li)for car in cars:item[title] car.xpath(./div[classm_detail]//a/text()).get()item[price] car.xpath(./div[classm_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://wiki.neutronadmin.com/news/87780/

相关文章:

  • 外贸常用的网站公共资源交易中心忙吗
  • 哪些网站可以做一些任务挣钱响应式全屏网站模板
  • 网站改版收费濮阳的网站建设
  • 山西品牌网站建设88个seo网站优化基础知识点
  • 这样建立网站wordpress插件随机文章
  • 怎样创建公司网站dw网站的站点建设
  • 网站服务建设网络应用软件开发
  • 中小型网站设计哪家好河北沧州泊头做网站的电话
  • 网站建设方面的知识推广赚佣金的平台
  • 新新手手网网站站建建设设铁盒 东莞网站建设
  • 湛江企业网站seo建设零食网站的可行性
  • 湛江网站建设公司centos wordpress ftp
  • 陶瓷 网站模板信息流网站建设
  • 网站后台空白商业网站策划书模板范文
  • 浙江省的网站建设公司有哪些网站建设的五类成员
  • 好看的企业网站源码网站建设公司扬州
  • 做场景秀的网站如何推广外贸型网站
  • 建站小程序编辑器闪亮登场用python做电商网站
  • 怎么制作微信购物网站山东大学信息服务平台
  • 婚庆网站建设策划案深圳房地产网站建设
  • 商城网站有什么好处黑色网站模板
  • 建设银行网站app一个大佬做的本子网站
  • 网站开发公司怎么选择网站开发者模式下载视频
  • 网站外包多少钱兰州市做网站的企业有哪些
  • 山东城市建设厅网站wordpress pdf 打印
  • 南京h5网站开发莱芜金点子电子版
  • 室内设计素材网站大全境外网站可以备案吗
  • 株洲建设企业网站oa系统网站建设
  • 深圳网站建设网站推广方案设计欣赏网
  • 做网站如何链接邮箱谷歌浏览器对做网站有什么好处