# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python模块之HTMLParser抓页面上的所有URL链接 import urllib
#MyParser类写法一
'''
from HTMLParser import HTMLParser
class MyParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self) def handle_starttag(self, tag, attrs):
if tag == 'a':
for name,value in attrs:
if name == 'href' and value.startswith('http'):
print value ''' #MyParser类写法二
import HTMLParser
class MyParser(HTMLParser.HTMLParser): def handle_starttag(self, tag, attrs):
     #这里重新定义了处理开始标签的函数
if tag == 'a':#判断标签<a>的属性
for name,value in attrs:
if name == 'href' and value.startswith('http'):#以什么字符串开头
print value if __name__ == '__main__':
url='http://www.cnblogs.com/'
content=urllib.urlopen(url).read()
my=MyParser()
my.feed(content)
my.close() '''
http://www.cnblogs.com/Jaryleely/p/careertwo.html
http://www.cnblogs.com/Jaryleely/
http://www.cnblogs.com/Jaryleely/
http://www.cnblogs.com/Jaryleely/p/careertwo.html#commentform
http://www.cnblogs.com/Jaryleely/p/careertwo.html
http://www.cnblogs.com/AndroidJotting/p/4983688.html
http://www.cnblogs.com/AndroidJotting/
http://www.cnblogs.com/AndroidJotting/
http://www.cnblogs.com/AndroidJotting/p/4983688.html#commentform
http://www.cnblogs.com/AndroidJotting/p/4983688.html
http://www.cnblogs.com/fuly550871915/p/4983682.html
http://www.cnblogs.com/fuly550871915/
http://www.cnblogs.com/fuly550871915/
http://www.cnblogs.com/fuly550871915/p/4983682.html#commentform
http://www.cnblogs.com/fuly550871915/p/4983682.html
http://www.cnblogs.com/Ray-liang/p/4983592.html
http://www.cnblogs.com/Ray-liang/
http://www.cnblogs.com/Ray-liang/
http://www.cnblogs.com/Ray-liang/p/4983592.html#commentform
http://www.cnblogs.com/Ray-liang/p/4983592.html
.......
'''

python模块之HTMLParser抓页面上的所有URL链接的更多相关文章

  1. python模块之HTMLParser(原理很大程度上就是对类构造的熟练运用)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser(原理很大程度上就是对类构造的熟练运用) import HTMLPar ...

  2. python模块介绍- HTMLParser 简单的HTML和XHTML解析器

    python模块介绍- HTMLParser 简单的HTML和XHTML解析器 2013-09-11 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq ...

  3. python模块之HTMLParser之穆雪峰的案例(理解其用法原理)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser之穆雪峰的案例(理解其用法原理) #http://www.cnblog ...

  4. python模块之HTMLParser解析出URL链接

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser解析出URL链接 #http://www.cnblogs.com/mf ...

  5. python模块之HTMLParser

    HTMLParser是python用来解析html的模块.它可以分析出html里面的标签.数据等等,是一种处理html的简便途径. HTMLParser采用的是一种事件驱动的模式,当HTMLParse ...

  6. history.pushState 实现浏览器页面不刷新修改url链接

    最近遇到了在不刷新页面的情况下修改浏览器url链接的需求,遂求助于万能的度娘,最终通过history.pushState()完美解决问题.现在将我理解的一些内容分享一下,不对的地方欢迎大家指出. 在使 ...

  7. python模块学习---HTMLParser(解析HTML文档元素)

    HTMLParser是Python自带的模块,使用简单,能够很容易的实现HTML文件的分析. 本文主要简单讲一下HTMLParser的用法. 使用时需要定义一个从类HTMLParser继承的类,重定义 ...

  8. python模块之HTMLParser简介

    html.parser是一个非常简单和实用的库,它的核心是HTMLParser类. 工作的流程是:当你feed给它一个类似HTML格式的字符串时,它会调用goahead方法向前迭代各个标签,并调用对应 ...

  9. python爬虫初级--获取指定页面上的菜单名称以及链接,然后导出

    ''' Created on 2017年4月5日 @author: Admin ''' import requests from bs4 import BeautifulSoup as bsp # 网 ...

随机推荐

  1. Ubuntu 查找文件的方法

    1. whereis+文件名 用于程序名的搜索,搜索结果只限于二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s),如果省略参数,则返回所有信息. 2. find / -name ...

  2. Statistical Artifact (error)

    In natural science and signal processing, an artifact is any error in the perception or representati ...

  3. [转]RSYNC 参数中文详解

    FROM : http://www.qiansw.com/rsync-cn.html rsync是一款好用的*nux文件同步工具.下面是其参数的中文解释. Rsync 参数选项说明 -v, --ver ...

  4. Java 内存管理白皮书

    1. 垃圾回收器 职责 分配内存 保证有引用对象不被回收 保证无引用对象被回收 设计方式 串行(Serial)与并行(Parallel) 串行的回收方式, 每次只能执行一种操作. 例如, 在多 cpu ...

  5. go语言之进阶篇接口的定义和实现以及接口的继承

    1.接口的定义和实现以及接口的继承 示例: package main import "fmt" //定义接口类型 type Humaner interface { //方法,只有声 ...

  6. EntityFramework6 快速入门教程【转】

    https://www.cnblogs.com/wujingtao/p/5401113.html 不得不说EF在国内实在是太小众,相关的技术文章真实屈指可数,而且很多文章都很旧了,里面使用的版本跟如今 ...

  7. Android开发Tips(5)

    欢迎Follow我的GitHub, 关注我的CSDN. 介绍关于Android的一些有趣的小知识点. 本文是第五篇了, 差点儿一周一篇, 欢迎阅读. 其余第一篇, 第二篇, 第三篇, 第四篇. 1. ...

  8. Shark简介、部署及编译小结

    http://blog.csdn.net/pelick/article/details/11964291 Shark简介 Shark即Hive on Spark,本质上是通过Hive的HQL解析,把H ...

  9. 如何用Docker建立一个Node.js的开发环境

      建立一个文件夹 用管理员身份打开powershell. 在文件夹下面运行npm init, 根据提示填入信息,以便产生一个package.json文件. 在文件中加入需要的dependencies ...

  10. linux 安装elasticsearch 可能遇到的问题

    1.can not run elasticsearch as root 切换到非root用户 因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户 第一步:liunx创 ...