我正在尝试生成[url_audioenci,url_caratula,titulo_cancion,nombre_artista]数组,以从http://los40.com.ar/lista40/下载音乐列表。我知道如何使用请求库下载媒体,但是我无法提取页面中的链接和链接
from bs4 import BeautifulSoup
import requests
# import re
url = 'http://los40.com.ar/m/lista40/'
videos = []
response = requests.get(url)
bs = BeautifulSoup(response.text)
for i in range (1,41):
videos[i]= bs.find_all('datos_camcion_'+i))
# responses= bs.find_all('script', language="javascript", type="text/javascript")
print(videos)
<h3>LISTA DEL 08/06/2019</h3>
<script language="javascript" type="text/javascript">
var datos_cancion_1 = Array();
datos_cancion_1['url_audioenci'] = 'https://recursosweb.prisaradio.com/audios/dest/570005645440.mp4';
datos_cancion_1['url_muzu'] = '';
datos_cancion_1['url_youtube'] = 'https://www.youtube.com/watch?v=XsX3ATc3FbA';
datos_cancion_1['url_itunes'] = '';
datos_cancion_1['posicion'] = '1';
datos_cancion_1['url_caratula'] = 'https://recursosweb.prisaradio.com/fotos/dest/570005645461.jpg';
datos_cancion_1['titulo_cancion'] = 'Boy with luv';
datos_cancion_1['nombre_artista'] = 'BTS;Halsey';
datos_cancion_1['idYes'] = 'BTS';
datos_cancion_1['VidAu'] = 0;
</script>
我希望
videos=[['https://recursosweb.prisaradio.com/audios/dest/570005645440.mp4','https://recursosweb.prisaradio.com/fotos/dest/570005645461.jpg','Boy with luv','BTS;Halsey'].....]
答案 0 :(得分:0)
我尝试过滤数据:
from bs4 import BeautifulSoup
import requests
url = 'http://los40.com.ar/m/lista40/'
videos = []
response = requests.get(url)
bs = BeautifulSoup(response.text, features="html5lib")
scripts = bs.find_all('script', language='javascript', type='text/javascript')
end = len( bs.find_all('script', language='javascript', type='text/javascript') )
start = end - 40
data = []
for i in range( start, end ):
data.append( str(scripts[ i ]) )
print( data[0] )
输出:
<script language="javascript" type="text/javascript">
var datos_cancion_1 = Array();
datos_cancion_1['url_audioenci'] = 'https://recursosweb.prisaradio.com/audios/dest/570005645440.mp4';
datos_cancion_1['url_muzu'] = '';
datos_cancion_1['url_youtube'] = 'https://www.youtube.com/watch?v=XsX3ATc3FbA';
datos_cancion_1['url_itunes'] = '';
datos_cancion_1['posicion'] = '1';
datos_cancion_1['url_caratula'] = 'https://recursosweb.prisaradio.com/fotos/dest/570005645461.jpg';
datos_cancion_1['titulo_cancion'] = 'Boy with luv';
datos_cancion_1['nombre_artista'] = 'BTS;Halsey';
datos_cancion_1['idYes'] = 'BTS';
datos_cancion_1['VidAu'] = 0;
</script>
Data [0:39]包含字符串的前40位和所有相关数据,但是我不确定如何从字符串中提取信息 。
在this thread中通过import json
或import re
提出了一些建议,但我无法使它们起作用。