python提取页面内的url列表,python提取页面url,python提取页面内的
python提取页面内的url列表,python提取页面url,python提取页面内的
python提取页面内的url列表
from bs4 import BeautifulSoupimport time,re,urllib2t=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()-tscanpage("http://news.163.com/")
相关内容
- python正则表达式提取网页URL,python正则表达式,python正则
- 用Python实现二分查找,Python实现二分查找,#!/usr/bin/e
- python妹子图简单爬虫,python妹子爬虫,#!/usr/bin/e
- python爬虫-urllib2库的有一些高级用法,python-urllib2,impo
- 根据IP地址和子网掩码算出网段,ip地址子网掩码算出
- 复制文件到指定目录(根据最近时间(天数和秒数))
- python通过mechanize模块实现不断刷新网页的功能,python
- python获取远程图片的大小和尺寸,,这段代码通过urlli
- python在windows下实现ping操作并接收返回信息,pythonping
- python用来获得图片exif信息的库代码,,exif-py是一个纯
评论关闭