翻看自己以前寫的程序,發(fā)現(xiàn)寫過一個(gè)爬取盤多多百度云資源的東西,完全是當(dāng)時(shí)想看變形金剛才自己寫的,而且當(dāng)時(shí)第一次接觸python/198178.html">python大概寫了有2天才搞出來這個(gè)程序,學(xué)習(xí)python語言,可以看得出來那時(shí)候的代碼寫的真的low。雖然現(xiàn)在也不怎么樣,哈哈,一直學(xué)習(xí)中,不做過多解釋,上圖上代碼,因?yàn)樽兞康穆暶魇鞘裁次易约阂餐耍ㄊ謩?dòng)傲嬌),連寫入文件當(dāng)時(shí)都不會(huì)哈哈哈哈哈哈哈哈,也不知道class中可以通過init初始化,唉學(xué)習(xí)python原來我學(xué)到了這么多東西,感謝python

from bs4 import BeautifulSoupimport urllibimport requestsimport readr =[]''''對(duì)搜素資源名字進(jìn)行url編碼'''search_text =raw_input('請(qǐng)輸入搜索資源名:')search_text = search_text.decode('gbk')search_text = search_text.encode('utf-8')search_text = urllib.quote(search_text)''''獲取文件地址'''home = urllib.urlopen('http://www.panduoduo.net/s/name/'+search_text)'''獲取百度云地址'''def getbaidu(adr): for i in adr: url = urllib.urlopen('http://www.panduoduo.net'+i) bs = BeautifulSoup(url) bs1 = bs.select('.dbutton2') href = re.compile('http/%(/%|/d|/w|////|//|/.)*') b = href.search(str(bs1)) name = str(bs.select('.center')).decode('utf-8') text1 = re.compile('/<h1/sclass/=/"center"/>[/d|/w|/D|/W]*/</h1/>') text2 = text1.search(name) rag1 = re.compile('/>[/d|/w|/D|/W]*/<') if text2: text3 = rag1.search(text2.group()) if text3: print text3.group() if b: text = urllib.unquote(str(b.group())).decode('utf-8') print text'''初始化'''def init(adr): soup = BeautifulSoup(home) soup = soup.select('.row') pattern = re.compile('//r///d+') for i in soup: i = str(i) adress = pattern.search(i) adress = adress.group() adr.append(adress)print 'running---------' init(adr)getbaidu(adr)以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選