首页 运维 网络学院 查看内容

网络爬虫爬取站点地图 python 抓取

2016-12-28 17:14 1759 0

摘要: 为了抓 取网站 ,我们首先需要下载包含有感兴趣数据的网页,该过程一般 被称为爬取(crawling)。 爬取 一个网站 有 很多种方法,而选用哪种方法更加 合适,则取决于目标网站 的结构 。 首先会探讨如何安全地下载网 ...

为了抓 取网站 ,我们首先需要下载包含有感兴趣数据的网页,该过程一般 被称为爬取(crawling)。 爬取 一个网站 有 很多种方法,而选用哪种方法更加 合适,则取决于目标网站 的结构 。 首先会探讨如何安全地下载网页, 然后会介绍如下爬取网站 的 常见方法:

·爬取网站 地图1

·遍历每个网页的 数据库ID

· 跟踪网页链接 。

下载 网 页

要想爬取网页,我们首先需要将其下载下来。 下面的示例脚 本使用Python

的 urllib2 模块下载URL。

下面是爬去站点地图的脚本 python写的

上代码吧。废话不多说

# -*- coding: utf-8 -*-

import re

from common import download

def crawl_sitemap(url):

# download the sitemap file

sitemap = download(url)

# extract the sitemap links

links = re.findall('<loc>(.*?)</loc>', sitemap)

# download each link

for link in links:

html = download(link)

# scrape html here

# ...

if __name__ == '__main__':

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部