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

企业网站推广的方法有网站开发 百度编辑器

企业网站推广的方法有,网站开发 百度编辑器,什么是广告营销,辽阳微网站建设阳光热线问政平台 http://wz.sun0769.com/index.php/question/questionType?type4 爬取投诉帖子的编号、帖子的url、帖子的标题#xff0c;和帖子里的内容。 items.py import scrapyclass DongguanItem(scrapy.Item):# 每个帖子的标题title scrapy.Field()# 每个帖子的编…阳光热线问政平台 http://wz.sun0769.com/index.php/question/questionType?type4 爬取投诉帖子的编号、帖子的url、帖子的标题和帖子里的内容。 items.py import scrapyclass DongguanItem(scrapy.Item):# 每个帖子的标题title scrapy.Field()# 每个帖子的编号number scrapy.Field()# 每个帖子的文字内容content scrapy.Field()# 每个帖子的urlurl scrapy.Field()spiders/sunwz.py Spider 版本 # -*- coding: utf-8 -*-import scrapy from dongguan.items import DongguanItemclass SunSpider(CrawlSpider):name sunallowed_domains [wz.sun0769.com]url http://wz.sun0769.com/index.php/question/questionType?type4pageoffset 0start_urls [url str(offset)]def parse(self, response):# 取出每个页面里帖子链接列表links response.xpath(//div[classgreyframe]/table//td/a[classnews14]/href).extract()# 迭代发送每个帖子的请求调用parse_item方法处理for link in links:yield scrapy.Request(link, callback self.parse_item)# 设置页码终止条件并且每次发送新的页面请求调用parse方法处理if self.offset 71130:self.offset 30yield scrapy.Request(self.url str(self.offset), callback self.parse)# 处理每个帖子里def parse_item(self, response):item DongguanItem()# 标题item[title] response.xpath(//div[contains(class, pagecenter p3)]//strong/text()).extract()[0]# 编号item[number] item[title].split( )[-1].split(:)[-1]# 文字内容默认先取出有图片情况下的文字内容列表content response.xpath(//div[classcontentext]/text()).extract()# 如果没有内容则取出没有图片情况下的文字内容列表if len(content) 0:content response.xpath(//div[classc1 text14_2]/text()).extract()# content为列表通过join方法拼接为字符串并去除首尾空格item[content] .join(content).strip()else:item[content] .join(content).strip()# 链接item[url] response.urlyield itemCrawlSpider 版本 # -*- coding: utf-8 -*- import scrapy from scrapy.linkextractors import LinkExtractor from scrapy.spiders import CrawlSpider, Rule from dongguan.items import DongguanItem import timeclass SunSpider(CrawlSpider):name sunallowed_domains [wz.sun0769.com]start_urls [http://wz.sun0769.com/index.php/question/questionType?type4page]# 每一页的匹配规则pagelink LinkExtractor(allow(type4))# 每个帖子的匹配规则contentlink LinkExtractor(allowr/html/question/\d/\d.shtml)rules [# 本案例为特殊情况需要调用deal_links方法处理每个页面里的链接Rule(pagelink, process_links deal_links, follow True),Rule(contentlink, callback parse_item)]# 需要重新处理每个页面里的链接将链接里的‘Typetype4?pagexxx’替换为‘Type?type4pagexxx’或者是Typepagexxx?type4’替换为‘Type?pagexxxtype4’否则无法发送这个链接def deal_links(self, links):for link in links:link.url link.url.replace(?,).replace(Type, Type?)print link.urlreturn linksdef parse_item(self, response):print response.urlitem DongguanItem()# 标题item[title] response.xpath(//div[contains(class, pagecenter p3)]//strong/text()).extract()[0]# 编号item[number] item[title].split( )[-1].split(:)[-1]# 文字内容默认先取出有图片情况下的文字内容列表content response.xpath(//div[classcontentext]/text()).extract()# 如果没有内容则取出没有图片情况下的文字内容列表if len(content) 0:content response.xpath(//div[classc1 text14_2]/text()).extract()# content为列表通过join方法拼接为字符串并去除首尾空格item[content] .join(content).strip()else:item[content] .join(content).strip()# 链接item[url] response.urlyield itempipelines.py # -*- coding: utf-8 -*-# 文件处理类库可以指定编码格式 import codecs import jsonclass JsonWriterPipeline(object):def __init__(self):# 创建一个只写文件指定文本编码格式为utf-8self.filename codecs.open(sunwz.json, w, encodingutf-8)def process_item(self, item, spider):content json.dumps(dict(item), ensure_asciiFalse) \nself.filename.write(content)return itemdef spider_closed(self, spider):self.file.close()settings.py ITEM_PIPELINES {dongguan.pipelines.DongguanPipeline: 300, }# 日志文件名和处理等级 LOG_FILE dg.log LOG_LEVEL DEBUG在项目根目录下新建main.py文件,用于调试 from scrapy import cmdline cmdline.execute(scrapy crawl sunwz.split())执行程序 py2 main.py
http://www.hkea.cn/news/14556665/

相关文章:

  • 公司网站建设推广方案建设购物网站需要多少费用
  • phpstud可以做几个网站信阳住房和城乡建设局网站
  • 庐山市建设规划局网站您提供的产品已经提交过网站备案
  • 泰安市建设职工培训中心网站官网WordPress文章添加灯箱
  • 网站改版怎么办做网站什么一级导航二级导航
  • 广州建设网站哪家好淄博做网站优化
  • 加关键词的网站北京公司摇号
  • ftp网站怎么建深圳做营销网站设计
  • 企业网站制作心得wordpress queryposts
  • 如何做好网站开发项目需求分析网站建设的前景
  • 珠海专业做网站公司做二维码网站
  • 网站网上商城建设方案成都专业网站排名推广
  • 关于免费制作网页的网站怎么下载网站的模板
  • 网站空间内存百度网站关键词排名查询
  • 没有英文网站怎么做外贸制作单位网站
  • 亚马逊没有网站怎么做seo做百度手机网站优化快
  • 嘉兴自助建站系统河南怎么样做网站
  • 南昌网站建设价位定制衣柜设计方案
  • 郑州做网站哪家好兴宁公司注册
  • 怎样建设企业网站 用于宣传网络舆情的特点
  • python 网站开发 案例网络推广方式有哪几种
  • 微博建网站策略网页游戏排行榜
  • 龙岗做网站公司哪家好建站模板怎么选
  • 手机怎么做网站卖东西百色高端网站建设
  • we建站做直播网站找哪个网站
  • 广东建设厅证件查询网站百度推广去哪里学技术
  • 软件it网站建设方案wordpress优质主题
  • 做自己照片视频网站vs做网站开发
  • 机械技术支持东莞网站建设加强部门网站建设工作
  • 浙江网站建设哪家权威游戏云服务器租用