python分析网页上所有超链接的方法

yipeiwu_com6年前Python基础

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

import urllib, htmllib, formatter
website = urllib.urlopen("http://yourweb.com")
data = website.read()
website.close()
format = formatter.AbstractFormatter(formatter.NullWriter())
ptext = htmllib.HTMLParser(format)
ptext.feed(data)
for link in ptext.anchorlist:
  print(link)

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

相关文章

使用pandas read_table读取csv文件的方法

read_csv是pandas中专门用于csv文件读取的功能,不过这并不是唯一的处理方式。pandas中还有读取表格的通用函数read_table。 接下来使用read_table功能作...

Python 字符串换行的多种方式

第一种: x0 = '<?xml version="1.0"?>' \ '<ol>' \ ' <li><a hr...

python读取Kafka实例

python读取Kafka实例

1. 新建.py文件 # pip install kafka-python from kafka import KafkaConsumer import setting conf...

python sqlobject(mysql)中文乱码解决方法

UnicodeEncodeError: 'latin-1' codec can't encode characters in position; 找了一天终于搞明白了,默认情况下,mys...

python3连接mysql获取ansible动态inventory脚本

Ansible Inventory  介绍 Ansible Inventory 是包含静态 Inventory 和动态 Inventory 两部分的,静态 Inventory...