python scrapy之爬取 zhengfu网站
来源:互联网 发布:人工智能阅读语文答案 编辑:程序博客网 时间:2024/05/18 02:56
#encoding=utf8import scrapyfrom govinfos.items import GovinfosItemclass GovInfos(scrapy.Spider): # 启动爬虫的名称 name = 'govinfo' # 爬虫的范围 allowed_domains=['xzqh.mca.gov.cn'] # 爬虫的第一个url # start_urls = ['http://xzqh.mca.gov.cn/fuzzySearch'] # 这里是用post请求数据的 def start_requests(self): url = 'http://xzqh.mca.gov.cn/fuzzySearch' # FormRequest 是Scrapy发送POST请求的方法 yield scrapy.FormRequest( url = url, formdata = {"fs" : "%"}, callback = self.parse ) # 爬取结果分析 def parse(self, response): print('%'*30) # print(response.body) node_list = response.xpath("//*[@class='info_table']/tr") for node in node_list: # 根据jiansuo_table 进行判断是否包含,若不包含,则为城市的第一个名称 # 第一个城市的第一个名称 td1 = node.xpath("./td[@class='name_left']/a/text()").extract() shen_address = node.xpath("./td/table[@class='jiansuo_table']/tr[@class='name_left']/td/a[@class='sheng_td']/text()").extract() shi_address = node.xpath("./td/table[@class='jiansuo_table']/tr[@class='name_left']/td/a[@class='shi_td']/text()").extract() qu_address = node.xpath("./td/table[@class='jiansuo_table']/tr[@class='name_left']/td[3]/a/text()").extract() print('%' * 30) print(td1) print(shen_address) print(shi_address) print(qu_address) # 驻地 zhudi_address =node.xpath("./td[@class='name_left']/text()").extract() print(zhudi_address) # renkou person = node.xpath("./td[3]/text()").extract() print(person) #面积 area = node.xpath("./td[4]/text()").extract() print(area) # 行政区划 xingzhen = node.xpath("./td[5]/text()").extract() print(xingzhen) # 区号 quhao = node.xpath("./td[6]/text()").extract() print(quhao) # 邮编 # print(node) youbian = node.xpath("./td[7]/text()").extract() print(youbian)
阅读全文
0 0
- python scrapy之爬取 zhengfu网站
- python+scrapy+mysql爬取故事网站
- 用Python 的 Scrapy 爬取 网站
- scrapy爬取电影网站
- python爬虫scrapy之贷联盟黑名单爬取
- Scrapy之图片爬取。
- scrapy(一)爬取动态网站
- scrapy框架爬取校花网站
- scrapy+xpath爬取不可描述网站
- python scrapy爬取动态页面
- Python Scrapy 学习----自动爬取网页
- python-scrapy-爬取图片笔记
- Python使用Scrapy爬取妹子图
- Python+Scrapy 爬取豆瓣电影排行榜Top250
- python + Scrapy 爬取动态网页
- python scrapy框架爬取CNKI数据
- Python爬虫框架Scrapy之爬取糗事百科大量段子数据
- python,scrapy爬虫sql之爬取数据存储到mysql的piplelines.py配置
- 浅谈 MVP in Android
- recycleView的条目长按换位置
- 昨天的代码
- HDU 6069 Counting Divisors 思路题(附赠大神代码)
- poj-1664 放苹果
- python scrapy之爬取 zhengfu网站
- javascript的日期函数
- Android ViewDragHelper完全解析 自定义ViewGroup神器
- XYNU OJ 1104: 例题6-8 单词统计
- ViewDragHelper实战 自己打造Drawerlayout
- 从零开始搭建环境编写操作系统 AT&T GCC (四)绘制界面
- Reading Note: ThiNet: A Filter Level Pruning Method for Deep Neural Network Compression
- minetest mod 初步学习
- 数据库的简单理解学习和使用