python提取页面内url列表的方法
2015-05-25 12:27
661 查看
本文实例讲述了python提取页面内url列表的方法。分享给大家供大家参考。具体实现方法如下:
from bs4 import BeautifulSoup import time,re,urllib2 t=time.time() websiteurls={} def scanpage(url): websiteurl=url t=time.time() n=0 html=urllib2.urlopen(websiteurl).read() soup=BeautifulSoup(html) pageurls=[] Upageurls={} pageurls=soup.find_all("a",href=True) for links in pageurls: if websiteurl in links.get("href") and links.get("href") not in Upageurls and links.get("href") not in websiteurls: Upageurls[links.get("href")]=0 for links in Upageurls.keys(): try: urllib2.urlopen(links).getcode() except: print "connect failed" else: t2=time.time() Upageurls[links]=urllib2.urlopen(links).getcode() print n, print links, print Upageurls[links] t1=time.time() print t1-t2 n+=1 print ("total is "+repr(n)+" links") print time.time()-t scanpage("http://news.163.com/")
希望本文所述对大家的Python程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- python提取页面内url列表的方法
- Python实现从url中提取域名的几种方法
- python+selenium打印当前页面的titl和url方法
- python提取字典key列表的方法
- Python 2.7_爬取CSDN单页面利用正则提取博客文章及url_20170114
- Python实现从URL地址提取文件名的方法
- python提取字典key列表的方法
- js中对arry数组的各种操作小结 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据 web前端url传递值 js加密解密 HTML中让表单input等文本框为只读不可编辑的方法 js监听用户的键盘敲击事件,兼容各大主流浏览器 HTML特殊字符
- python使用正则表达式提取网页URL的方法
- Python实现从url中提取域名的几种方法
- python爬虫主要就是五个模块:爬虫启动入口模块,URL管理器存放已经爬虫的URL和待爬虫URL列表,html下载器,html解析器,html输出器 同时可以掌握到urllib2的使用、bs4(BeautifulSoup)页面解析器、re正则表达式、urlparse、python基础知识回顾(set集合操作)等相关内容。
- python抽取指定url页面的title方法
- Python实现从URL地址提取文件名的方法
- Python自动化脚本【1】url提取及自动打开页面
- Python实现从url中提取域名的几种方法
- Python 2.7_爬取CSDN单页面博客文章及url(二)_xpath提取_20170118
- Python抓取页面中超链接(URL)的三中方法比较(HTMLParser、pyquery、正则表达式) <转>
- java 页面url传值中文乱码的解决方法。
- 【Python+OpenCV】视频流局部区域像素值处理-一种特征提取方法