I'm trying to automatize a download of subtitles from a public website. The subtitles are accesible once you click on the download link (Descargar in spanish). Inspecting the code of the website, I can see that the links are jQuery events:
There is a function inside this event that, I guess, deals with the download (I'm not at all familiar with JS):
function(a) {
if (ajaxflagon()) return !1;
var r = $(this).attr("rel");
if (r = r.split(","), 3 == r.length) var e = "/updated/" + r[0] + "/" + r[1] + "/" + r[2];
else var e = "/original/" + r[0] + "/" + r[1];
ga("send", "pageview", "/" + e, {
title: "Descargando " + $(this).attr("title")
}), $(this).attr("href", e), ajaxflagoff()
}
So far, I have code that finds the proper links:
import urllib.request as urlRequest
from bs4 import BeautifulSoup
# Subtitles for a specific TV show
urlpage = 'https://www.tusubtitulo.com/season/4674/1'
# pretend to be a chrome 47 browser on a windows 10 machine
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)"
}
req = urlRequest.Request(urlpage, headers=headers)
# open the url
url = urlRequest.urlopen(req)
# get the source code
source_code = url.read()
# parse the html using beautiful soup and store in variable 'soup'
soup = BeautifulSoup(source_code, 'html.parser')
results = []
for lang in soup.findAll("td", class_="language"):
# only interested in the spanish language
if "Español (España)" in str(lang):
for element in lang.parent.findAll("a", class_="bt_descarga"):
results.append(element)
What it's missing is the download part :( How can I do it?
Thanks in advance.
