初識(shí)python urllib爬取百度云連接

翻看自己以前寫的程序,發(fā)現(xiàn)寫過一個(gè)爬取盤多多百度云資源的東西,完全是當(dāng)時(shí)想看變形金剛才自己寫的,而且當(dāng)時(shí)第一次接觸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

cmd圖片
from bs4 import BeautifulSoup
import urllib
import requests
import re

adr =[]

''''對(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)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,381評(píng)論 25 708
  • 一、異同對(duì)比選擇1、Python和ruby的相同點(diǎn): * 都強(qiáng)調(diào)語法簡單,都具有更一般的表達(dá)方式。python是縮...
    沃倫蓋茨閱讀 4,187評(píng)論 2 24
  • PPT 視頻鏈接 一、背景介紹: 傳統(tǒng)的it架構(gòu)的缺陷: 使用傳統(tǒng)的整體式架構(gòu)(Monolithic Archit...
    LeeZer閱讀 21,767評(píng)論 2 6
  • 你好建樹
    連暢閱讀 130評(píng)論 0 0