Reputation: 523
How to scrape all value from a DropDown menu in a website? For example in this website
There is this DropDown menu:
I want to get all value and save it into an array structure that's have also a link of the relative nation, for example:
Afghanistan => http://it.soccerway.com/national/afghanistan/afghan-premier-league/2015/regular-season/r32792/
Albania => http://it.soccerway.com/national/albania/super-league/20152016/regular-season/r31891/
Algeria => http://it.soccerway.com/national/algeria/ligue-1/20152016/regular-season/r31583/
...
How I can achieve this result?
Upvotes: 2
Views: 1733
Reputation: 205987
This might also be helpful (using one line of PHP): jQuery load external site page
Inspect element, right click and Copy HTML, Paste it inside your .html file.
Here's a glimpse of that HTML structure:
<ul class="list hidden">
<li>Club Domestic (1085)</li>
<li data-value="/national/afghanistan/a8/?ICID=SN_02_01">Afghanistan (1)</li>
var LI = document.querySelectorAll(".list li");
var result = {};
for(var i=0; i<LI.length; i++){
var el = LI[i];
var elData = el.dataset.value;
if(elData) result[el.innerHTML] = elData; // Only if element has data-value attr
}
console.log( result );
Upvotes: 1