python爬取百度雲網盤資源-源碼

今天測試用了一下python爬取百度雲網盤資源.

代碼片段

import urllib
import urllib.request
import webbrowser  
import re
def yunpan_search(key):
    keyword = key
    keyword = keyword.encode('utf-8')
    keyword = urllib.request.quote(keyword)
    url = "http://www.wangpansou.cn/s.php?q="+keyword+"&wp=0&start=0"
    #webbrowser.open(url) 
    req = urllib.request.Request(url, headers = {
        'Connection': 'Keep-Alive',
        'Accept': 'text/html, application/xhtml+xml, */*',
    'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'
})
    opener = urllib.request.urlopen(req)
    html = opener.read()
    html = html.decode('utf-8')
    rex = r'https?://pan.baidu.com.*\?uk=[0-9]{10}.*[\d+?]"'
    m = re.findall(rex,html)
    f = open('/root/Desktop/txt.txt','w')
    for i in m:
        f.write(i)
        f.write('\n\n')
    f.close();
    print("抓取成功!")

if __name__=='__main__':
    print('爬取百度雲盤資源快捷爬取')
    key = input('輸入你想搜索的資源:')
    yunpan_search(key)

在學習過程中有什麼不懂得可以加我的
python學習交流扣扣qun,784758214
羣裏有不錯的學習視頻教程、開發工具與電子書籍。
與你分享python企業當下人才需求及怎麼從零基礎學習好python,和學習什麼內容
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章