python提取頁(yè)面內(nèi)url列表的方法
更新時(shí)間:2015年05月25日 12:27:51 作者:小蘿莉
這篇文章主要介紹了python提取頁(yè)面內(nèi)url列表的方法,涉及Python操作頁(yè)面元素的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了python提取頁(yè)面內(nèi)url列表的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
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/")
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- python實(shí)現(xiàn)圖片處理和特征提取詳解
- Python進(jìn)行數(shù)據(jù)提取的方法總結(jié)
- 在Python中使用NLTK庫(kù)實(shí)現(xiàn)對(duì)詞干的提取的教程
- python-opencv在有噪音的情況下提取圖像的輪廓實(shí)例
- 詳解Python3中字符串中的數(shù)字提取方法
- python實(shí)現(xiàn)提取百度搜索結(jié)果的方法
- python 根據(jù)正則表達(dá)式提取指定的內(nèi)容實(shí)例詳解
- python讀取視頻流提取視頻幀的兩種方法
- Python實(shí)現(xiàn)的特征提取操作示例
相關(guān)文章
Python實(shí)現(xiàn)前端樣式尺寸單位轉(zhuǎn)換
在?Web?前端項(xiàng)目開(kāi)發(fā)時(shí),樣式尺寸都是以?rpx?為單位,可是?UI?設(shè)計(jì)師在看完開(kāi)發(fā)后的?UI?,卻要求都以?px?為單位,所以本文就和大家分享一個(gè)利用Python就能實(shí)現(xiàn)尺寸單位轉(zhuǎn)換的方法吧2023-06-06python多線程http下載實(shí)現(xiàn)示例
python多線程http下載實(shí)現(xiàn)示例,大家參考使用吧2013-12-12pytorch-gpu安裝的經(jīng)驗(yàn)與教訓(xùn)
本文主要介紹了pytorch-gpu安裝的經(jīng)驗(yàn)與教訓(xùn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2023-01-01Python檢查 云備份進(jìn)程是否正常運(yùn)行代碼實(shí)例
這篇文章主要介紹了Python檢查 云備份進(jìn)程是否正常運(yùn)行代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08Python如何把不同類型數(shù)據(jù)的json序列化
這篇文章主要介紹了Python如何把不同類型數(shù)據(jù)的json序列化,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-04-04