Python实现抓取页面上链接
2015-08-30 09:19
866 查看
方法一:
# 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
# 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-9.4 对象的真值
- 零基础学python-9.4 对象的真值
- 零基础学python-9.3 对象的比较
- 零基础学python-9.3 对象的比较
- IDA pro 的Python环境变量设置
- Python通过pyserial控制串口操作
- Python工具
- Python 遍历文件查找不同
- 初探python的__init__.py
- 简单Python脚本实现数据导出Excel格式的尝试
- 【python】strip()的用法
- 【python】socket编程常量错误问题-1 'AF_INET'
- 2015/8/29 Python基础(3):数值
- Python 自学笔记(二)第一个程序 Hello World
- Python中文分词组件jieba
- Python 2.7和NLTK安装教程
- python使用xmlrunner模块生成报告举例
- Python 自学笔记(一)环境搭建
- Setup Python 开发环境和IPython的基本使用
- 零基础学python-9.2 文件