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,和学习什么内容

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...