今天測試用了一下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,和學習什么內容
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
