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

歡迎訪問 生活随笔!

生活随笔

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

python

python 获取foobar2000官网全部插件

發布時間:2023/12/10 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 获取foobar2000官网全部插件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

foobar2000是音樂愛好者最喜愛的音頻播放器之一。用戶可以根據實際需求為它增加插件來增強使用體驗。而foobar2000官網提供了上百個插件供用戶下載,但是如果要全部下載則需要花費大量時間,所以在這里我提供一種思路來下載foobar2000的全部插件。
基本思路是要獲取插件的全部下載鏈接。
首先解析

http://www.foobar2000.org/components

發現有形似

<a href="/components/view/foo_input_vio2sf">...</a>

這樣的代碼
而其中

/components/view/foo_input_vio2s

就是我們要的網址
所以首要目標是獲取全部這樣的地址

import requests from bs4 import BeautifulSoupwith open(r'foobar2000_components.txt','w',encoding='utf-8') as fp:url='http://www.foobar2000.org/components'r=requests.get(url)soup=BeautifulSoup(r.text,'lxml')for item in soup.find_all('a'):k=item.get('href'fp.write(k+'\n')

獲取的文本如下:
額,好像多了點東西
加一個判斷語句

import requests from bs4 import BeautifulSoupwith open(r'foobar2000_components.txt','w',encoding='utf-8') as fp:url='http://www.foobar2000.org/components'r=requests.get(url)soup=BeautifulSoup(r.text,'lxml')components=[]for item in soup.find_all('a'):k=item.get('href')if 'tag' not in k and 'components/view' in k:if k+'\n' not in components: #去重components.append(k+'\n') for item in components:fp.write(item)

如圖:

這樣就差不多了,但這只是插件介紹頁的網址,所以還要逐個解析這些網址來獲取下載鏈接

fp1=open(r'foobar2000_components.txt','r',encoding='utf-8') fp2=open(r'foobar2000_components_download.txt','w',encoding='utf-8') lines=fp1.readlines() urls=[] for i in range(len(lines)):urls.append('http://www.foobar2000.org'+lines[i]) headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36'} for url in urls:r=requests.get(url[0:-1], headers = headers)soup=BeautifulSoup(r.text,'lxml')for item in soup.find_all('a'):k=item.get('href')if 'getcomponent' in k:fp2.write(k[1:]+'\n' fp1.close() fp2.close()

這樣就獲得了全部的下載鏈接
最后把這兩個過程整合一下

import requests from bs4 import BeautifulSoupwith open(r'foobar2000_components_get.txt','w',encoding='utf-8') as fp:r=requests.get('http://www.foobar2000.org/components')soup=BeautifulSoup(r.text,'lxml')urls=[]for item in soup.find_all('a'):k=item.get('href')if 'tag' not in k and 'components/view' in k:if k not in urls: #去重urls.append(k)headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36'}for url in urls:r=requests.get('http://www.foobar2000.org'+url, headers = headers)soup=BeautifulSoup(r.text,'lxml')for item in soup.find_all('a'):k=item.get('href')if 'getcomponent' in k:fp.write('http://www.foobar2000.org'+k+'\n')

不過筆者實際運行的時候發現有幾個插件因為服務器超時沒有獲取下載鏈接,需要跳過錯誤繼續運行,所以最后只獲取了一部分,但也無傷大雅
然后下載:

from urllib import request with open(r'foobar2000_components_get.txt','r') as fp:urls=fp.readlines()local='d:\\components\\'for url in urls:i=url.rfind('/'request.urlretrieve(url[0:-1],local+url[i+1:-1])

最后整合后的全部代碼如下:

import requests from bs4 import BeautifulSoup from urllib import requestr=requests.get('http://www.foobar2000.org/components') soup=BeautifulSoup(r.text,'lxml') urls=[] for item in soup.find_all('a'):k=item.get('href')if 'tag' not in k and 'components/view' in k:if k not in urls: #去重urls.append(k) #獲取下載頁面網址 headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36'} download_urls=[] for url in urls:try:r=requests.get('http://www.foobar2000.org'+url, headers = headers)soup=BeautifulSoup(r.text,'lxml')for item in soup.find_all('a'):k=item.get('href')if 'getcomponent' in k:download_urls.append('http://www.foobar2000.org'+k) #獲取下載鏈接except:continue local='d:\\components\\' for url in download_urls:i=url.rfind('/')request.urlretrieve(url,local+url[i+1:] #下載文件

完成

雖說授人以魚不如授人以漁,不過還是貼一下全插件的下載鏈接吧
https://www.lanzous.com/i7u1wwh
密碼:7w9b

總結

以上是生活随笔為你收集整理的python 获取foobar2000官网全部插件的全部內容,希望文章能夠幫你解決所遇到的問題。

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