mercredi 29 juin 2016

How to choose option on a web drop down box?


I'm using Python 3.5.1, and I need to automate the download of a bunch of reports every morning (through Python). These are imported from a web platform, which is of restricted access. I started with the following piece of code, which works fine:

import webbrowser, time
webbrowser.open('mylink')
time.sleep(10)

However, I'm struggling now with a drop down box, from which I have to choose and submit the location. Here's the HTML necessary to solve the problem:

<SELECT id=PRMT_SV_N000000000C88F800x000000000E8040B8_NS_ class="clsSelectControl pv" aria-invalid=false style="WIDTH: auto" hasLabel="true">
  <OPTION selected>MDM Location Code</OPTION>
  <OPTION>--------------------------------------------</OPTION>
  <OPTION value=3002 dv="3002  Ontario 002">3002&nbsp;&nbsp;Ontario&nbsp;&nbsp;002</OPTION>
  <OPTION value=3004 dv="3004  Fresno, CA  004">3004&nbsp;&nbsp;Fresno,&nbsp;CA&nbsp;&nbsp;004</OPTION>
  <OPTION value=3005 dv="3005  San Diego

The Finish/submit button HTML:

<BUTTON onclick="oCV_NS_.promptAction('finish')" onmouseover="this.className = 'bp bph'" onmouseout="this.className = 'bp'" id=finishN000000000C88F800x000000000E804A58_NS_ class=bp name=finishN000000000C88F800x000000000E804A58_NS_>Finish</BUTTON>

I have omitted most of the options of course. For this exercise, imagine that I want to choose the first one, 3004 Fresno, CA 004.


Aucun commentaire:

Enregistrer un commentaire