python提取页面内url列表的方法
作者:小萝莉 时间:2022-12-26 15:29:27
本文实例讲述了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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
提高ASP性能的最佳选择第二部分
2007-08-15 12:46:00
Django静态文件加载失败解决方案
2021-05-25 19:40:47
![](https://img.aspxhome.com/file/2023/2/68872_0s.png)
python使用selenium打开chrome浏览器时带用户登录信息实现过程详解
2023-07-19 05:00:37
![](https://img.aspxhome.com/file/2023/8/60298_0s.jpg)
pandas行和列的获取的实现
2022-06-05 07:57:49
Python使用中文正则表达式匹配指定中文字符串的方法示例
2021-11-28 22:17:00
![](https://img.aspxhome.com/file/2023/0/86430_0s.png)
MATLAB数学建模之画图汇总
2023-06-14 06:49:50
![](https://img.aspxhome.com/file/2023/1/59291_0s.png)
JavaScript实现自动变换表格边框颜色
2024-06-07 15:25:53
SQL Server中使用判断语句(IF ELSE/CASE WHEN )案例
2024-01-18 22:04:53
如何做一个文本搜索?
2010-07-12 19:00:00
python+pygame实现坦克大战
2023-12-04 10:52:38
![](https://img.aspxhome.com/file/2023/9/124229_0s.jpg)
Mysql更换MyISAM存储引擎为Innodb的操作记录总结
2024-01-22 05:54:25
python区块链创建多个交易教程
2021-05-28 13:40:42
python实现一个围棋小游戏
2022-02-02 18:52:50
![](https://img.aspxhome.com/file/2023/6/90536_0s.png)
sql server中datetime字段去除时间的语句
2024-01-23 17:47:57
python新手练习实例之万年历
2021-01-29 02:20:35
vuex中数据持久化插件vuex-persistedstate使用详解
2024-04-26 17:41:54
![](https://img.aspxhome.com/file/2023/2/133122_0s.png)
SQL Server中的排名函数与分析函数详解
2024-01-17 03:28:54
![](https://img.aspxhome.com/file/2023/1/122351_0s.png)
Docker安装MySQL8.0的实现方法
2024-01-23 06:52:06
![](https://img.aspxhome.com/file/2023/1/128001_0s.jpg)
奇妙的Javascript图片放大镜
2024-04-30 08:51:22
Git在Windows中安装与使用教程
2023-11-01 08:47:55
![](https://img.aspxhome.com/file/2023/5/67205_0s.png)