首页 > 编程语言 > 详细

Python实现抓取页面上链接

时间:2015-08-30 09:56:39      阅读:156      评论:0      收藏:0      [点我收藏+]
方法一: 
# coding:utf-8
import re
import requests
# 获取网页内容
r = requests.get(http://www.163.com)
data = r.text
# 利用正则查找所有连接
link_list =re.findall(r"(?<=href=\").+?(?=\")|(?<=href=\‘).+?(?=\‘)" ,data)
for url in link_list:
    print url
 
方法二:
 
import urllib2
import re
#connect to a URL
website = urllib2.urlopen(url)
#read html code
html = website.read()
#use re.findall to get all the links
links = re.findall("((http|ftp)s?://.*?)", html)
for url in links:
    print url 
 

Python实现抓取页面上链接

原文:http://www.cnblogs.com/shellr00t/p/4770336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!