Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to analyse Chilean elections data available in the official website. What I have returns the data for president (numbers are strings, to be parsed later).

Import["http://www.eleccionservel.cl/ELECCIONES2013/vistaPaisPresidente", "Data"][[2, 2, 2, 2, 2 ;; 10, {1, 3, 4}]]

But to get the data for congress, the website does not have a direct URL and the data by districts needs to be selected by clicking in links that look like this

<a href="#" onclick="javascript:doSubmit('409','D');"> Distrito 9 </a>

Which in turn runs

function doSubmit(a,b){document.consultarForm.codigo.value=a;document.consultarForm.nivel.value=b;document.consultarForm.submit()}
<form id="diputado" name="consultarForm" action="/ELECCIONES2013/diputado" method="POST">

I have tried unsucessfully the following

url="http://www.eleccionservel.cl/ELECCIONES2013/diputado";
Import[url, "Data", "RequestMethod" -> "POST", "RequestParameters" -> {   "codigo" -> "409",   "nivel" -> "D",   "division" -> "POLITICA",   "codigoPadre" -> "409",   "codigoCircunscripcion" -> "409",   "codigoColegio" -> "D"   }]

Not sure if "RequestParameters" should refer to the "name" or the "id" of the form.

Is there a chance to get this data with Mathematica in an elegant and simple way, or should I be looking to a different tool?

share|improve this question
1  
(Nothing personal in flagging this question for closing. The issue appears to have more to do with an opaque Javascript-manipulated HTML form, not to do with Mathematica, in which your syntax was correct and fine.) –  Andrew Cheong Nov 18 '13 at 12:17
    
@acheong87 I guess the question was about finding a way around opaque Javascript-manipulated HTML form, using Mathematica. The solutions uses a non-documented feature and I thought I may have misunderstood it's use. Sorry if the question seems to be out of topic, it is my first post in here and I did try my best to apply due diligence. –  rhermans Nov 18 '13 at 13:12
    
No, in light of that view, your question may have been perfectly relevant—I'm new to Mathematica.SE myself and I don't pretend to have any authoritative view on this. That said, I'm doubtful Mathematica should be able to help in that regard, because then Mathematica would have to be able to not only understand Javascript (a monumental task in itself, but then again, I may be underestimating Mathematica), but also determine what code is relevant. What happens, for example, if the website uses a complex jQuery extension to validate form fields before submitting the form conditionally? –  Andrew Cheong Nov 18 '13 at 13:36

1 Answer 1

up vote 4 down vote accepted

Your code works fine—the site is just very stringent on the data supplied. I used Chrome's Inspect Element to see the values of all the input elements (including the hidden fields, as you'd noticed)—and I found that sometimes codigoColegio was left blank:

Inspect Element

It didn't work when I filled out codigoColegio to match nivel as you seemed to have done, but it did work when I followed the input fields exactly:

Results

(The copy-pasteable code is already in OP's post, so supplying a screenshot for convenience.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.