Perry Harold
pharold at proftesting.com
Fri Apr 29 13:48:12 CDT 2005
Marty, Stuart, Drew
Thanks for the help. Guess I have to find time to get it up and running
now.
Perry Harold
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of MartyConnelly
Sent: Wednesday, April 27, 2005 3:57 PM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] Pushing data to a web page
You can do this with xmlhttp and web scraping, you just have to know how
the web post form works
just find the submission button name and textbox name from the html source
>From this movie web form the select button is named "select" and the
text box "for"
Then add to Send in xml call
All this code below is equivalent to the url
http://www.imdb.com/Find?select=All&for="Sahara"
Then run code below to dump to an html file or string which can be parsed.
This won't work if the html changes or the site obfuscates the form to
stop this with page redirects.
partial HTML source from
"http://www.imdb.com/Find"
<TD valign="top" width="100%">
<SELECT name="select">
<OPTION selected>
All
</OPTION>
<OPTION>
Titles
</OPTION>
<OPTION>
Plots
</OPTION>
</SELECT><BR clear="left">
<INPUT type="text" name="for" size=
"14"> <INPUT type="image" height="21"
width="31" border="0" value="Go" name="Go"
src="http://i.imdb.com/f163.gif" align=
"absmiddle"><BR clear="left">
'FindMovie ("Sahara")
Public Function FindMovie(strTitle As String) As String
' Dim oHttp As MSXML2.XMLHTTP
Dim oHttp As Object
Dim strFileNameH As String
Dim strFileNameT As String
Dim strSend As String
Dim strSubmit As String
Dim strStockName As String
'make use of the XMLHTTPRequest object contained in msxml.dll
Set oHttp = CreateObject("Microsoft.XMLHTTP")
' Set oHttp = CreateObject("MSXML2.XMLHTTP")
'set according to form type
'oHttp.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
'oHttp.setRequestHeader "Content-Type", "text/xml"
'oHttp.setRequestHeader "Content-Type", "multipart/form-data"
oHttp.Open "POST", "http://www.imdb.com/Find", False
oHttp.send "select=All&for=" & strTitle
'oHttp.send (strSend)
' oHttp.send
Debug.Print "strSend=" & strSend
'check the feedback
Debug.Print "Ready State =" & oHttp.readyState
'normal state =4
Debug.Print "Status =" & oHttp.status
'normal status = 200
' Debug.Print "Status Text =" & oHttp.statusText
Debug.Print oHttp.getAllResponseHeaders()
'Debug.Print "Response Body =" & oHttp.responseBody
' Debug.Print "Response Body =" & StrConv(oHttp.responseBody, vbUnicode)
'Debug.Print "Response Text =" & oHttp.responseText
'Parse response text string here or send to file
strFileNameH = "c:\Accesshtmlstealer\Amazon"
strFileNameH = strFileNameH & Format(Now, "yyyymmddhhmmss") & ".htm"
WriteFile strFileNameH, oHttp.responseText
' HypeLinkFile strFileNameH
strFileNameT = "c:\Accesshtmlstealer\Amazon"
strFileNameT = strFileNameT & Format(Now, "yyyymmddhhmmss") & ".txt"
WriteFile strFileNameT, oHttp.responseText
'
FindMovie = strFileNameH
Exit Function
ErrorHandler:
MsgBox Err.Description & vbCrLf & Err.Number
'
Resume Next
End Function
Public Sub WriteFile(ByVal sFileName As String, ByVal sContents As String) '
Dump XML String to File for debugging
Dim fhFile As Integer
fhFile = FreeFile
' Debug.Print "Length of string=" & Len(sContents)
Open sFileName For Output As #fhFile
Print #fhFile, sContents;
Close #fhFile
Debug.Print "Out File" & sFileName
End Sub
Public Sub ReadFile(ByVal sFileName As String, ByRef sContents As String) '
Dump XML String to File for debugging Dim strLine As String Dim intLine As
Long Dim fhFile As Integer
intLine = 0
sContents = ""
fhFile = FreeFile
' Debug.Print "Length of string=" & Len(sContents)
Open sFileName For Input As #fhFile
Do While Not EOF(1) ' Loop until end of file.
Input #1, strLine ' Read data
intLine = intLine + 1
sContents = sContents & strLine
'Debug.Print sContents ' Print data to Debug window.
Loop
Close #fhFile ' Close file.
Debug.Print "Input File" & sFileName & " lines=" & intLine End Sub Perry
Harold wrote:
>Drew
>
>Do you perhaps have a sample of going the other way - Retrieving from a
>web page? I regularly access a site to retrieve data for one of my
>databases. Go to main page - select by an id number and then clip some
>of the data. Would like to automate if possible.
>
>Perry Harold
>
>-----Original Message-----
>From: dba-vb-bounces at databaseadvisors.com
>[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of
>DWUTKA at marlow.com
>Sent: Tuesday, April 26, 2005 10:36 AM
>To: dba-vb at databaseadvisors.com
>Subject: RE: [dba-VB] Pushing data to a web page
>
>
>Just sent you an example offlist.
>
>Drew
>
>-----Original Message-----
>From: John W. Colby [mailto:jwcolby at colbyconsulting.com]
>Sent: Tuesday, April 26, 2005 9:11 AM
>To: 'Access Developers discussion and problem solving'; VBA
>Subject: [dba-VB] Pushing data to a web page
>
>
>Does anyone know how to manipulate a web page from VB/VB.net? I need
>to place values in text boxes, click radio buttons, click command
>buttons etc.
>
>John W. Colby
>www.ColbyConsulting.com
>
>Contribute your unused CPU cycles to a good cause:
>http://folding.stanford.edu/
>
>
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com
>
>
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com
>
>
>
>
>
--
Marty Connelly
Victoria, B.C.
Canada
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com