国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python使用scrapy抓取網(wǎng)站sitemap信息的方法

2020-02-23 00:36:57
字體:
供稿:網(wǎng)友

本文實例講述了Python使用scrapy抓取網(wǎng)站sitemap信息的方法。分享給大家供大家參考。具體如下:

import refrom scrapy.spider import BaseSpiderfrom scrapy import logfrom scrapy.utils.response import body_or_strfrom scrapy.http import Requestfrom scrapy.selector import HtmlXPathSelectorclass SitemapSpider(BaseSpider): name = "SitemapSpider" start_urls = ["http://www.domain.com/sitemap.xml"] def parse(self, response):  nodename = 'loc'  text = body_or_str(response)  r = re.compile(r"(<%s[/s>])(.*?)(</%s>)"%(nodename,nodename),re.DOTALL)  for match in r.finditer(text):   url = match.group(2)   yield Request(url, callback=self.parse_page) def parse_page(self, response):    hxs = HtmlXPathSelector(response)    #Mock Item  blah = Item()  #Do all your page parsing and selecting the elemtents you want    blash.divText = hxs.select('//div/text()').extract()[0]  yield blah

希望本文所述對大家的Python程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 连江县| 诸城市| 商丘市| 望谟县| 兴化市| 丽江市| 墨脱县| 友谊县| 康定县| 汉川市| 吉安市| 大丰市| 卓资县| 霍林郭勒市| 贺兰县| 塘沽区| 兴义市| 东阳市| 金昌市| 荣成市| 庄浪县| 舞钢市| 盖州市| 紫金县| 临漳县| 木兰县| 临湘市| 巴中市| 云阳县| 阿瓦提县| 黄山市| 安新县| 札达县| 酒泉市| 万载县| 浦北县| 介休市| 兴仁县| 溆浦县| 屯昌县| 修武县|