python多執行緒實現抓取網頁

2021-09-07 17:02:00 字數 1148 閱讀 8780

python實現抓取網頁

以下的python抓取網頁的程式比較0基礎。僅僅能抓取第一頁的url所屬的頁面,僅僅要預定url足夠多。保證你抓取的網頁是無限級別的哈,以下是**:

##coding:utf-8

''' 無限抓取網頁

@author wangbingyu

@date 2014-06-26

'''import sys,urllib,re,thread,time,threading

''''''

class download(threading.thread):

def __init__(self,url,threadname):

threading.thread.__init__(self,name=threadname)

self.thread_stop = false

self.url = url

def run(self):

while not self.thread_stop:

self.list = self.geturl(self.url)

self.downloading(self.list)

def stop(self):

self.thread_stop = true

def downloading(self,list):

try:

for i in range(len(list) - 1):

urllib.urlretrieve(list[i],'e:\upload\download\%s.html' % time.time())

except exception,ex:

print exception,'_upload:',ex

def geturl(self,url):

result =

s = urllib.urlopen(url).read();

ss = s.replace(' ','')

urls=re.findall('

python多執行緒爬蟲抓取網頁

突發想法,抓取 資料以便採用機器學習分析練手,網頁為年份。步驟如下 1 每乙個子執行緒抓取每一年的網頁 2 抓取網頁後利用正規表示式抽取資料,存入多維list。3 構建sql語句,存入mysql。user bin env python3 coding utf 8 from bs4 import be...

CURL多執行緒抓取網頁

網上這類方法似乎太多了。但是總是有一些問題存在。對於多執行緒抓取,現在有如下幾種思路 1.用apache的多執行緒特性,讓php進行 多程序 操作,就像post本身一樣 2.用curl的curl multi庫 對於第一種,我還沒嘗試,因為這種製造的是偽多執行緒,也許效率會低很多,而且不好控制。第二種...

c 多執行緒抓取網頁內容

1.2.好了,認識 分析完問題,就是解決問題了 多執行緒在c 中並不難實現。它有乙個命名空間 system.threading 提供了多執行緒的支援。要開啟乙個新執行緒,需要以下的初始化 threadstart startdownload new threadstart download 執行緒起始...