简体   繁体   中英

Android webscrape - How to download a file from a site when the site uses a javascript download function

I am using Jsoup in my app to scrape data from a site. Everything was fine until I came across the 'download' part of the app. It would be easy if the download link is in the href value but this site uses a javascript function

Here's how the site is layed out:

This is the link to the file:

<a href="javascript:download(11848,'d915f46123');">Ai Ai Ai ni Utarete Bye Bye Bye</a>

Below is the javascript download function. It accepts a songid and a key, builds a string with the passed arguments and sets it as the form's action attribute, and calls the form's submit method:

function download(songId, key) {
var form = document.getElementById('dlForm'); form.action = '/download/zephzeph/' + key + '/' + songId + '.mp3';
form.submit();
}

Below is the form:

<form id="dlForm" action="/amusic/download.php" method="POST"></form>

Hopefully I understand your question correctly, do elaborate, if not.

I would try to right click on the download link and open it in a new tab. The new link is what you need to emulate in your scraper.

My experience with net scraping is very limited, but I would be more than happy to help you find a solution. :)

Looks like the only way I can achieve this is to use a webview. http://android-er.blogspot.com/2011/10/call-javascript-inside-webview-from.html?m=1 . I'll try and see if it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM