• 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求素数示例分享
  • 用Python的线程来解决生产者消费问题的示例
  • Windows系统下安装Python的SSH模块教程
  • python的keyword模块用法实例分析
  • Python中内置数据类型list,tuple,dict,set的区别和用法
  • Pycharm学习教程(5) Python快捷键相关设置
  • Python3.x中自定义比较函数
  • python中readline判断文件读取结束的方法
  • Python设计模式之观察者模式实例
  • python文件写入实例分析

文章分类

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

最近更新的内容

    • 使用python检测手机QQ在线状态的脚本代码
    • Python在图片中添加文字的两种方法
    • Python单例模式实例分析
    • Python实现全角半角转换的方法
    • Python读写配置文件的方法
    • OpenCV实现人脸识别
    • 在tensorflow中设置保存checkpoint的最大数量实例
    • 合并百度影音的离线数据( with python 2.3)
    • Python中的ceil()方法使用教程
    • Python 分析Nginx访问日志并保存到MySQL数据库实例

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

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