日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python3 爬取乐谱

發(fā)布時間:2023/12/29 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3 爬取乐谱 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


最近感覺找樂譜下載之類比較麻煩, 于是花了兩天時間寫了個爬蟲程序, 效率倍增。

使用方法: 在https://www.17jita.com上搜索樂譜,點開第一個界面,將網(wǎng)址按程序內格式賦給url_sa下,然后運行,便可以在D:/pic/目錄下獲得樂譜。


效果如下:



源碼(日后有時間會繼續(xù)完善):

import urllib.request import re import os from bs4 import BeautifulSoup#database recipeWeb = "https://www.17jita.com/" recipeWeb_len = len(recipeWeb)webList = [] FinalList = []url_sa = "tab/img/4289" url = recipeWeb + url_sa + '.html'def getList(url):data = getData(url)pre = r'href='post = r'.*?html'webList = findPreAndPost(pre, post , data) return webListdef findPreAndPost(pre, post, data):loc = []res = []length = re.split(r'\s', data)for i in length:if(re.match(pre,i)):loc.append(i)for i in loc:if(re.match(post,i)):res.append(i)return resdef getData(url):webPage = urllib.request.urlopen(url)data = webPage.read()data = data.decode('gbk')return datadef GetPic(url, cnt):data = getData(url)soup = BeautifulSoup(data, 'html.parser')length = re.split(r'\s', data)title = soup.find('h1', {'class': 'ph'}).textloc = []res = []for i in length:if(re.match(r'src=',i)):loc.append(i)for i in loc:if(re.match(r'.*?png',i)):res.append(i)for pic in res:tmp = re.search(r'src="(.*?)"',pic)pic_url = tmp.group(1)print(pic_url)if(pic_url[0]=='/' or pic_url[0]!='h'): continue;pic_web = urllib.request.urlopen(pic_url)pic_data = pic_web.read()path = "d:/pic/"+title+'/';if not os.path.exists(path):os.makedirs(path)f = open(path+title+str(cnt)+".png","wb")f.write(pic_data)f.close()print(pic)webList = getList(url) FinalList.append(url) for i in webList:cnt = 0searchStr = 'href="'+ url_sa + '(.*?)"'tmp = re.search(searchStr, i)if tmp:ans = tmp.group(1)W = recipeWeb+url_sa+ansif not W in FinalList:FinalList.append(W)cnt = 0 for web_url in FinalList:cnt += 1GetPic(web_url, cnt)

總結

以上是生活随笔為你收集整理的python3 爬取乐谱的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。