• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python使用scrapy抓取网站sitemap信息的方法

Python使用scrapy抓取网站sitemap信息的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了scrapy抓取动态页面,scrapy抓取图片,scrapy抓取动态网页,python爬虫scrapy,python scrapy等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python使用scrapy抓取网站sitemap信息的方法。分享给大家供大家参考。具体如下:

import re
from scrapy.spider import BaseSpider
from scrapy import log
from scrapy.utils.response import body_or_str
from scrapy.http import Request
from scrapy.selector import HtmlXPathSelector
class 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
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python使用scrapy抓取网站sitemap信息的方法
  • Python使用scrapy抓取网站sitemap信息的方法

相关文章

  • Python使用面向对象方式创建线程实现12306售票系统
  • python中列表元素连接方法join用法实例
  • 浅谈python中的实例方法、类方法和静态方法
  • Python通过RabbitMQ服务器实现交换机功能的实例教程
  • 栈和队列数据结构的基本概念及其相关的Python实现
  • Python中对列表排序实例
  • Python获取apk文件URL地址实例
  • Windows下使Python2.x版本的解释器与3.x共存的方法
  • Python类的用法实例浅析
  • Python上传package到Pypi(代码简单)

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python类的专用方法实例分析
    • 关于Python面向对象编程的知识点总结
    • Python单链表的简单实现方法
    • python目录与文件名操作例子
    • python xml.etree.ElementTree遍历xml所有节点实例详解
    • python使用calendar输出指定年份全年日历的方法
    • python将图片文件转换成base64编码的方法
    • python 实现归并排序算法
    • python语言使用技巧分享
    • python 网络编程常用代码段

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有