• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Web Scraping - click a drop down menu

mike p

New Member
Hi there,
I wrote some code to help automate a web scraping process but the last bit of my code wont work, "With Mybrowser.document .queryselector /end with" portion. The goal is to click a drop down menu then click submit to have it return the data. I've included the html code that I'm trying to scrape below the code.
Any help is greatly appreciated.


Code:
Dim HMTLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub daily()
'
' daily Macro
'

 Dim MyHTML_Element As IHTMLElement
  Dim MYURL As String
  ' website
  MYURL = ""
  Set MyBrowser = New InternetExplorer
  MyBrowser.Silent = True
  MyBrowser.navigate MYURL
  MyBrowser.Visible = True
  Do
  Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
  Set HTMLDoc = MyBrowser.document
  ' user login and password
  HTMLDoc.all.user_login.Value = "**"
  HTMLDoc.all.user_password.Value = "**"
  ' click submit
  HTMLDoc.forms(0).submit
  While MyBrowser.Busy Or MyBrowser.readyState < 4: DoEvents: Wend
  ' click reports
  HTMLDoc.getElementsByClassName("menuitem")(1).Click
  While MyBrowser.Busy Or MyBrowser.readyState < 4: DoEvents: Wend
  'click Billing Analysis Report (Industrial)
  HTMLDoc.getElementsByClassName("firstlink")(0).Click
  While MyBrowser.Busy Or MyBrowser.readyState < 4: DoEvents: Wend

  With MyBrowser.document
  .querySelector("select[name=vsCustKy]").Click
  .querySelector("option[value=1745]").Selected = True
  .querySelector("select[name=vsCustKy]").FireEvent "onchange"
 
 End With

  HTMLDoc.forms(0).submit

End Sub

HTML:
</SCRIPT><LINKrel="stylesheet"href="https://www.conectiv.com/cpd/cpd_stylesheet.css"></HEAD><BODYbgcolor="#ffffff"leftmargin="0"marginwidth="0"marginheight="0"topmargin="0"background="https://www.conectiv.com/images/big_c_bg.gif"bgproperties="fixed"vlink="#1f969b"link="#1f969b"onLoad="window.query_form.vsReportMonth.focus();"><!-- Begin: CPD Navigation Header --><tableborder="0"cellpadding="0"cellspacing="0"><tr><tdnowrapvalign="bottom"><ahref="https://www.delmarva.com"><imgsrc="https://webapps.delmarva.com/images/delmarva_logo.png"border="0"align="middle"alt="Delmarva Power"></a></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></table><!-- End: CPD Navigation Header --><TABLEborder="1"cellpadding="6"cellspacing="0"width="100%"bordercolor="#cccccc"><TR><tdcolspan="1"align="center"><tableborder="0"cellpadding="0"cellspacing="0"width="100%"><tr><tdalign="left"valign="middle"nowrap><ahref="gso_etrader_main?vsCurrUser=2753"class="menuitem">Trader Home</a><spanclass="body"> | </span><ahref="gso_list_etrader_transaction?vsCurrUser=2753"class="menuitem">Transaction</a><spanclass="body"> | </span><ahref="gso_list_etrader_reports?vsCurrUser=2753"class="menuitem">Reports</a></td></tr></table></td></TR><TR><TD><CENTER><BR><TABLEWIDTH=500CELLSPACING=0><TR><THVALIGN=TOPALIGN=LEFT><FONTCOLOR="BLUE"FACE="Arial, Helvetica"SIZE="4"><B>INPUT THE MONTH & YEAR :</B></FONT></TH></TR></TABLE><FORMACTION="gso_billing_analysis_report"METHOD="POST"NAME="query_form"onSubmit="return verify_entries();"><INPUTTYPE="hidden"NAME="vsCurrUser"VALUE="2753"><INPUTTYPE="hidden"NAME="vsTransactionName"VALUE="INTER_BILLING_ANALYSIS_REPORT"><TABLEWIDTH=500CELLSPACING=0><TR><TD><TABLEWIDTH=500BGCOLOR="#FFFFFF"BORDER=1CELLSPACING=0><TR><TDALIGN=LEFTVALIGN=TOP><TABLEWIDTH=500CELLSPACING=0><TR><TDALIGN=LEFTCOLSPAN=2><FONTCOLOR="BLUE"FACE="Arial, Helvetica"SIZE="2"> &nbsp; </FONT></TD></TR><TR><TDWIDTH=200ALIGN=RIGHTVALIGN=CENTER><FONTCOLOR="BLACK"FACE="Arial, Helvetica"SIZE="2"><B>MONTH :&nbsp;</B></FONT></TD><TDWIDTH=300ALIGN=LEFTVALIGN=CENTER><SELECTNAME="vsReportMonth"><OPTIONVALUE=1>January <OPTIONVALUE=2>February <OPTIONVALUE=3>March <OPTIONVALUE=4>April <OPTIONVALUE=5>May <OPTIONVALUE=6>June <OPTIONVALUE=7>July <OPTIONSELECTEDVALUE=8>August <OPTIONVALUE=9>September <OPTIONVALUE=10>October <OPTIONVALUE=11>November <OPTIONVALUE=12>December </SELECT></TD></TR><TR><TDALIGN=LEFTCOLSPAN=2><FONTCOLOR="BLUE"FACE="Arial, Helvetica"SIZE="2"> &nbsp; </FONT></TD></TR><TR><TDWIDTH=200ALIGN=RIGHTVALIGN=CENTER><FONTCOLOR="BLACK"FACE="Arial, Helvetica"SIZE="2"><B>YEAR :&nbsp;</B></FONT></TD><TDWIDTH=300ALIGN=LEFTVALIGN=CENTER><FONTCOLOR="BLACK"FACE="Arial, Helvetica"SIZE="2"><INPUTTYPE="TEXT"NAME="vsReportYear"VALUE="2018"SIZE=4MAXLENGTH=4></FONT></TD></TR><TR><TDALIGN=LEFTCOLSPAN=2><FONTCOLOR="BLUE"FACE="Arial, Helvetica"SIZE="2"> &nbsp; </FONT></TD></TR><TR><TDWIDTH=200ALIGN=RIGHTVALIGN=TOP><FONTCOLOR="BLACK"FACE="Arial, Helvetica"SIZE="2"><B>CUSTOMER :&nbsp;</B></FONT></TD><TDWIDTH=300ALIGN=LEFTVALIGN=TOP><FONTCOLOR="BLACK"FACE="Arial, Helvetica"SIZE="2"><SELECTNAME="vsCustKy"><OPTIONSELECTEDVALUE=1705>Diamond State Generation Partner (Brookside) (LVG- QFTP-RC) <OPTIONVALUE=1745>Diamond State Generation Partners (Red Lion) (LVG- QFTP-RC) </SELECT></FONT></TD></TR><TR><TDALIGN=LEFTCOLSPAN=2><FONTCOLOR="BLUE"FACE="Arial, Helvetica"SIZE="2"> &nbsp; </FONT></TD></TR><TR><TDALIGN=CENTERCOLSPAN=2><INPUTTYPE="submit"VALUE="Continue"></TD></TR><TR><TDALIGN=LEFTCOLSPAN=2><FONTCOLOR="BLUE"FACE="Arial, Helvetica"SIZE="2"> &nbsp; </FONT></TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE></FORM></CENTER><!-- Begin: CPD Navigation Footer --><tr><tdcolspan="1"align="center"><tableborder="0"width="100%"><tr><tdalign="center"><spanclass="caption">Copyright: 2018 Delmarva Power. All rights reserved</span></td></tr></table></td></tr></TABLE></BODY></HTML>
 
Back
Top