python获取指定网页上所有超链接的方法

yipeiwu_com5年前Python基础

本文实例讲述了python获取指定网页上所有超链接的方法。分享给大家供大家参考。具体如下:

这段python代码通过urllib2抓取网页,然后通过简单的正则表达式分析网页上的全部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)
print links

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

相关文章

python使用udp实现聊天器功能

python使用udp实现聊天器功能

聊天器简易版 使用udp实现一个简单的聊天器程序,要求如下: •在一个电脑中编写1个程序,有2个功能 •1.获取键盘数据,并将其发送给对方 •2.接收...

基于python调用psutil模块过程解析

这篇文章主要介绍了基于python调用psutils模块过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 用Python来编写脚...

基于python的列表list和集合set操作

基于python的列表list和集合set操作

以下是一些python的list和set的基本操作 1. list的一些操作 list = [1, 2, 3] list.append(5) print(list) list.e...

Python3.5内置模块之shelve模块、xml模块、configparser模块、hashlib、hmac模块用法分析

Python3.5内置模块之shelve模块、xml模块、configparser模块、hashlib、hmac模块用法分析

本文实例讲述了Python3.5内置模块之shelve模块、xml模块、configparser模块、hashlib、hmac模块用法。分享给大家供大家参考,具体如下: 1、shelve...

python增加矩阵维度的实例讲解

numpy.expand_dims(a, axis) Examples >>> x = np.array([1,2]) >>> x.shape...