中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

python簡單爬蟲

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

[Python]代碼    

import re
import urllib
import urllib.request
from collections import deque

queue = deque()#存放待爬取的網(wǎng)址
visited = set()#存放爬取過的網(wǎng)址。判斷是否爬取過

url = "http://news.dbanotes.net"#入口網(wǎng)站
queue.append(url)
count = 1

while queue:
	url = queue.popleft()#刪除已經(jīng)爬取過的隊首的網(wǎng)址url
	visited |= {url}#把已經(jīng)爬取過的頁面放入set中,方便下面的判斷
	urlop = urllib.request.urlopen(url)
	if 'html' not in urlop.getheader('Content-Type'):
		continue#如果是html再繼續(xù)爬取
	try:
		data = urlop.read().decode('utf-8')
	except:
		continue
	value = re.findall(r'href="(.+?)"',data)
	for x in value:
		if 'http' in x and x not in visited:
			print("加入隊列:" + x)

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:20個非常有用的Java程序片段

下一篇:文件下載java實現(xiàn)代碼