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 BeautifulSoup
with 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 BeautifulSoup
with 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