title: How to get download location from javascript link?
body: <p>I'm trying to programmatically download a pdf from <a href="https://www.yourticketprovider.nl/LiveContent/tickets.aspx?x=492449&amp;y=8687&amp;px=92AD8EAA22C9223FBCA3102EE0AE2899510C03E398A8A08A222AFDACEBFF8BA95D656F01FB04A1437669EC46E93AB5776A33951830BBA97DD94DB1729BF42D76&amp;rand=a17cafc7-26fe-42d9-a61a-894b43a28046&amp;utm_source=PurchaseSuccess&amp;utm_medium=Email&amp;utm_campaign=SystemMails" rel="nofollow">a website</a> in which the link loads some javascript:</p>
  
  <pre><code>&lt;a href="javascript:__doPostBack('downloadTop','')"&gt;Download&lt;/a&gt;
  </code></pre>
  
  <p>Seeing that a wget or any comparable mechanism would obviously fail I decided to use selenium with Phantomjs to emulate a real browser and javascript interpreter to actually see what it does if I "click" on the download link. According to <a href="https://github.com/ariya/phantomjs/issues/10052" rel="nofollow">this github issue</a> Phantomjs currently does not support file download. The thing is that I don't even need to download the file using Phantomjs, I just want to get the direct url from the file so that I can simply download it using something like wget.</p>
  
  <p>So I tried the following:</p>
  
  <pre><code>&gt;&gt;&gt; from selenium import webdriver
  &gt;&gt;&gt; driver = webdriver.PhantomJS()
  &gt;&gt;&gt; link = 'https://www.yourticketprovider.nl/LiveContent/tickets.aspx?x=492449&amp;y=8687&amp;px=92AD8EAA22C9223FBCA3102EE0AE2899510C03E398A8A08A222AFDACEBFF8BA95D656F01FB04A1437669EC46E93AB5776A33951830BBA97DD94DB1729BF42D76&amp;rand=a17cafc7-26fe-42d9-a61a-894b43a28046&amp;utm_source=PurchaseSuccess&amp;utm_medium=Email&amp;utm_campaign=SystemMails'
  &gt;&gt;&gt; driver.get(link)
  &gt;&gt;&gt; for linkElement in driver.find_elements_by_tag_name('a'):
  ...    print linkElement.get_attribute('href')
  ...    
  https://www.yourticketprovider.nl/
  javascript:__doPostBack('downloadTop','')
  https://www.yourticketprovider.nl/LiveContent/tickets.aspx?x=492449&amp;y=8687&amp;px=92AD8EAA22C9223FBCA3102EE0AE2899510C03E398A8A08A222AFDACEBFF8BA95D656F01FB04A1437669EC46E93AB5776A33951830BBA97DD94DB1729BF42D76&amp;rand=a17cafc7-26fe-42d9-a61a-894b43a28046&amp;utm_source=PurchaseSuccess&amp;utm_medium=Email&amp;utm_campaign=SystemMails#
  etc. etc.
  </code></pre>
  
  <p>Since I need to get the second element I tried the following:</p>
  
  <pre><code>&gt;&gt;&gt; a = driver.find_elements_by_tag_name('a')[1].click()
  &gt;&gt;&gt; print a
  None
  </code></pre>
  
  <p>and from here I'm kinda stuck. </p>
  
  <p>Does anybody know how I can click that link and get the resulting download url? All tips are welcome!</p>