-
Re: I need to get data form a web page
Option Explicit
Dim UPC As String
Dim Document
Dim getElementsByTagName
Dim Item
Dim innerText
Dim a
Dim b
Dim c
Dim d
Dim f
Dim z
Dim blnBusy As Boolean
Private Sub Command1_Click()
Dim i As Integer
'Navigate to the page
WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl"
'Both the readystate and the busy properties of the WB control
'are not completely reliable. The best way to wait for loading to take
'place I have found so far is using a custom boolean variable that
'is set in the BeforeNavigate2 and NavigateComplete2 events.
blnBusy = True
Do While blnBusy = True
DoEvents
Loop
'Fill in the upc number in the textbox with ID 'UPC'
'blnBusy = True
UPC = InputBox("Enter UPC Number", , "07800008846")
WebBrowser1.Document.getElementById("upc").Value = UPC
'Submit the first (and only) form in the page
WebBrowser1.Document.Forms.Item(0).submit
'Wait for the new page to load again
'blnBusy = True
Do While blnBusy = True
DoEvents
Loop
'Enumerate all TD tags in the document, because the info we want to extract
'is inside them.
For i = 0 To WebBrowser1.Document.getElementsByTagName("td").length - 1
Select Case WebBrowser1.Document.getElementsByTagName("td").Item(i).innerText
'If the text of the TD tag is one of the value names we're
'looking for, return the text in the second TD tag after it.
'As you can see in the source, all TD's with value names are
'followed by an empty TD tag and a TD tag containing the actual
'value. E.g. <td>Description</td><td></td><td>DR PEPPER CHER VAN 2LT</td>
Case "Description", "Size/Weight", "Manufacturer", "Entered/Modified"
MsgBox WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
a = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
z = WebBrowser1
b = Document
c = getElementsByTagName
d = Item
f = innerText
Open "c:\pos\bob.dat" For Append As #1
Print #1, a,
Print #1, z, b, c, d, f
'Print #1, z,
'Print #1, b
'Print #1, c
'Print #1, d
'Print #1, f
'Print #1,
Close #1
End Select
Next i
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
blnBusy = True
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
blnBusy = False
End Sub
Can you all fix for me?
It print one line and does not enter to print the next upc on the next line.
-
Re: I need to get data form a web page
VB Code:
Option Explicit
Dim UPC As String
Dim blnBusy As Boolean
dim field as string
dim ff as integer
dim lfield as integer
open app.path & "bob.dat" for APPEND as #ff
'
' use the old code up to here
'
For i = 0 To WebBrowser1.Document.getElementsByTagName("td").length - 1
Select Case WebBrowser1.Document.getElementsByTagName("td").Item(i).innerText
lfield=0
Case "Description"
ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
lfield = 1
case "Size/Weight"
ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
lfield = 1
case "Manufacturer"
ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
lfield = 1
case "Entered/Modified"
ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
lfield= 2
End Select
if lfield = 1
print #ff, chr$(34) & ifield & chr$(34) & ", " ;
elseif
if lfield=2
print #ff, chr$(34) & ifield & chr$(34)
endif
Next i
close #ff
End Sub
this should be the way that you want to do it.
-
Re: I need to get data form a web page
can you all fix the code for me.
-
Re: I need to get data form a web page
can you all help me get fix.
-
Re: I need to get data form a web page
Come on Bob, you can do it!
I too was unaware of the capabilities of the Document object always parsed text myself.
Thanks for the great examples Vader.
This is a great thread.
-
Re: I need to get data form a web page
Quote:
Originally Posted by RobDog888
I think this is the first step. It loads the page into the forms web browser. Then upon the command1 click
it will enter the upc into the web page's textbox and sends an enter keypress. Then the page returns
with the upc data.
VB Code:
Option Explicit
'Add component to Microsoft HTML Object Library
'Add component Microsoft Internet Controls
'Add a command button (Command1)
'Add a web browser control to the form (WebBrowser1)
Dim hDoc As MSHTML.HTMLDocument
Dim hInp As MSHTML.HTMLInputElement
Private Sub Command1_Click()
Set hInp = hDoc.getElementById("upc")
hInp.focus
hInp.Value = "07800008846"
SendKeys "{ENTER}", True
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl"
End Sub
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
WebBrowser1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight - 450 'Make adjustment for command button
End If
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Set hDoc = WebBrowser1.Document
End Sub
:thumb:
Hi rob, i am very interesting on this question and naturally on you work...
I use Excel and VBA...
For you is possible to arrange this your code to put value from a column of sheet and put into a box present on this site and after press the button SUBMIT:
http://www.canadapost.ca/tools/pcl/bin/advanced-e.asp
Tks in advance.
Sal.
-
Re: I need to get data form a web page
Instead of entering the code in the textbox, you could load the result page immediately by using parameters in the URL
http://www.upcdatabase.com/item.pl?upc=078000088465
-
Re: I need to get data form a web page
Quote:
Originally Posted by Frans C
But Frans, where would be the learning experience in doing that.
We want to write allot of code and use different techniques. :lol: Jk
:thumb:
-
Re: I need to get data form a web page
ok. I seem to have figured out the clicking part. I am now having a problem with submitting the info into the next textbox. I belive it's a problem with frames. I think the vb code is tring to paste the text in the first frame. this is not the correct frame.
VB Code:
Option Explicit
Dim blnBusy As Boolean
Private Sub Command1_Click()
Dim i As Integer
'set this so the loop doesnt enter to quickly
blnBusy = True
'load went here
'Navigate to the page
WebBrowser1.Navigate2 "http://www.onestopmotors.com/admin"
'Both the readystate and the busy properties of the WB control
'are not completely reliable. The best way to wait for loading to take
'place I have found so far is using a custom boolean variable that
'is set in the BeforeNavigate2 and NavigateComplete2 events.
Do While blnBusy = True
DoEvents
Loop
'Fill in the textboxs with user and pwd
WebBrowser1.Document.getElementById("txtUser").Value = "jason"
WebBrowser1.Document.getElementById("txtPwd").Value = "wopper"
WebBrowser1.Document.All.btnLogin.Click
'Submit went here
'Wait for the new page to load again
Do While blnBusy = True
DoEvents
Loop
'Enumerate all TD tags in the document, because the info we want to extract
'is inside them.
For i = 0 To WebBrowser1.Document.getElementsByTagName("td").length - 1
Select Case WebBrowser1.Document.getElementsByTagName("td").Item(i).innerText
'If the text of the TD tag is one of the value names we're
'looking for, return the text in the second TD tag after it.
'As you can see in the source, all TD's with value names are
'followed by an empty TD tag and a TD tag containing the actual
'value. E.g. <td>Description</td><td></td><td>DR PEPPER CHER VAN 2LT</td>
Case "Description", "Size/Weight", "Manufacturer", "Entered/Modified"
MsgBox WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
End Select
Next i
End Sub
Private Sub Command2_Click()
'Navigate to the page
WebBrowser1.Navigate2 "http://www.onestopmotors.com/admin"
End Sub
Private Sub Command3_Click()
WebBrowser1.Document.getElementById("txtsearch").Value = Text1.Text
WebBrowser1.Document.All.btnSearch.Click
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
blnBusy = True
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
blnBusy = False
End Sub
-
1 Attachment(s)
Re: I need to get data form a web page
can all test and fix it if it need to be fixed. I do not have vb 6.0 and I am use windows vist.
-
Re: I need to get data form a web page
Quote:
Originally Posted by Frans C
Yup possible that way, as long as you keep in mind that some sites don't support GET method, or may suddenly shift to POST for security reasons.
-
Re: I need to get data form a web page
-
Re: I need to get data form a web page
I can't access the page you guys are manipulating... do I need to register and is it free?
-
Re: I need to get data form a web page
no do not need to register
http://www.upcdatabase.com
I can go to it.
-
Re: I need to get data form a web page
How did you all get to page posted in post #26? I get an error page; resource not found for http://www.upcdatabase.com/nocheckdigit.pl
-
Re: I need to get data form a web page
the page have update then.
-
Re: I need to get data form a web page
can you help get get to work vb 08?
What is the new url http://www.upcdatabase.com/nocheckdigit.pl ?
-
Re: I need to get data form a web page
I get RESOURCE NOT FOUND when I click your link Bob.
-
Re: I need to get data form a web page
-
1 Attachment(s)
Re: I need to get data form a web page
I need to get the upc into Text1.
how do I do it.
Code:
Private Sub Command1_Click()
Dim ADOCn As ADODB.Connection
Dim ConnString As String
Dim sSQL As String
Dim iStart As Integer
Dim Text
Dim iEnd As Integer
iStart = 0
iEnd = 0
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Users\bob\Desktop\UPC\games.mdb;" & _
"Persist Security Info=False"
Set ADOCn = New ADODB.Connection
ADOCn.ConnectionString = ConnString
ADOCn.Open ConnString
Do While WebBrowser1.Busy = True
DoEvents
Sleep 500
Loop
Set hDoc = WebBrowser1.Document
Set hInp = hDoc.getElementById("upc")
'hInp.focus
'hInp.Value = "02881920"
'SendKeys "{ENTER}", True
'Find the UPC
iStart = InStr(1, hDoc.body.innerHTML, "<TD>upc</TD>") + 37
iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>")
'MsgBox upc
MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
Text1.Text = Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
Do While WebBrowser1.Busy = True
DoEvents
Sleep 500
Loop
Set hInp = Nothing
'Parse the elements and read the values of the data returned
'Set document variable = to the new results documents page
Set hDoc = WebBrowser1.Document
'Find the description:
iStart = InStr(1, hDoc.body.innerHTML, "<TD>Description</TD>") + 37
iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>")
MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
Text2.Text = Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
'Find the Size/Weight:
iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Size/Weight</TD>") + 37
iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>")
MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
Text3.Text = Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
'Find Manufacturer:
'iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Manufacturer</TD>") + 38
'iEnd = InStr(iStart, hDoc.body.innerHTML, "(<A href=")
'MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
'Text4.Text = Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
'Find the Entered/Modified:
'iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Entered/Modified</TD>") + 42
'iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>")
'MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
'Text5.Text = Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
sSQL = "INSERT INTO table " & "(UPC, Description) VALUES ('" & Text1.Text & "', '" & Text2.Text & "')"
Debug.Print sSQL
'ADOCn.Execute sSQL
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate2 "http://www.upcdatabase.com/item.pl"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
'Dim strConn As String
'Dim strSQL As String
'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Brandon Crocker\Desktop\SALES 1\SALES 1\Database.mdb;Persist Security Info=False"
'strSQL = "SELECT * FROM MemberDetails"
End Sub
-
Re: I need to get data form a web page
-
Re: I need to get data form a web page
-
Re: I need to get data form a web page
well
<form action="https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi" method="post">
<table cellpadding=5>
<tr>
<td>Login:</td>
<td><input type="text" name="login" size=16 style="width:100%" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" size=16 style="width:100%" /></td>
</tr>
<tr>
<td></td>
<td align=center><input type="submit" value="Premium Zone Login" /></td>
</tr>
</table>
</form>
login ok
password ok
submit ???? please
-
Re: I need to get data form a web page
-
Re: I need to get data form a web page
-
Re: I need to get data form a web page
I need the on in vb.net
Code:
Dim hDoc As MSHTML.HTMLDocument
Dim hInp As MSHTML.HTMLInputElement
Private Sub Command1_Click()
Set hInp = hDoc.getElementById("upc")
hInp.focus
hInp.Value = "07800008846"
SendKeys "{ENTER}", True
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl"
End Sub
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
WebBrowser1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight - 450 'Make adjustment for command button
End If
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Set hDoc = WebBrowser1.Document
End Sub
-
Re: I need to get data form a web page
-
Re: I need to get data form a web page
Quote:
Originally Posted by
bob5731
I need the on in vb.net
Hello bob5731,
If you have a VB.Net Question, it would be best if you were to ask it in the VB.Net Forum, that is where you have the best chance of getting an answer.
Gary