Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 88

Thread: I need to get data form a web page

  1. #41
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    I don't know if he got it working.

  2. #42
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: I need to get data form a web page

    Nice work with the control, Rob. Although your code could use some optimization. You can do more with the Document object model than you're doing now.

    For starters, you shouldn't need the Sleep command while you're waiting. The ReadyState property will perform better than Busy.
    VB Code:
    1. Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    2.     DoEvents
    3. Loop
    You don't have to focus the textbox in order to fill in the value or to click it. Calling the Click event on it is more reliable than using SendKeys.
    VB Code:
    1. hInp.Value = "07800008846"
    2. hInp.Click
    Finally, you don't have to use string manipulation to extract the data from the webpage. In this case, you could enumerate all TD tags with the getElementsByTagName method, then when the innerText property of a TD element is "Manufacurer", read out the next TD tag which contains text.

    If you want to learn more about the Web Browser control or the Document Object Model, read the articles in my sig.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  3. #43
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I need to get data form a web page

    Thanks Vad. I just put this together last night quickly, first time.

    I was having trouble with the .Click of the hInp object. Was stating a type mismatch or something.
    ReadyState vs Busy, didnt see that one. getElementsByTagName was giving issues too because the submit
    button doesnt have a id or name. What do you do in that case?

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #44
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    Vader, I downloaded your browser control a long time ago, but didn't see anything in it that I saw as being able to parse information from web pages. Do you have an example of how you could programmatically interact with a page or series of web pages?
    For instance, logging on to VBF and reading and or writing a Private message would be cool. And helpful. Any examples of automating would help.

  5. #45
    Hyperactive Member
    Join Date
    May 2001
    Location
    TZI Transition Date
    Posts
    272

    Re: I need to get data form a web page

    a very informative thread ! like the way ya got the page on the form...
    since i do this all the time for stock data i would add that using api URLDownloadToFile is prolly faster & no send keys needed...

    VB Code:
    1. Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    2.  
    3.     Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    4.         Dim lngRetVal As Long
    5.         lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    6.         If lngRetVal = 0 Then DownloadFile = True
    7.     End Function
    8.     Call DownloadFile("http://www.upcdatabase.com/item.pl?upc=078000088465", "c:\test.txt")
    9.    
    10.     'then parse test.txt...

  6. #46
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I need to get data form a web page

    Quote Originally Posted by dglienna
    For instance, logging on to VBF and reading and or writing a Private message would be cool...
    Dave, you should be careful. This could possibly be considered hacking the Forums - an AUP violation.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #47
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    Well, I was just trying to find a common site that most of us could use. I don't know how that would be hacking, as long as it was your own account, but whatever. I'd be just as happy with any site that has log on credentials.

    I've only seen one instance of this that actually worked.

  8. #48

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry Re: I need to get data form a web page

    '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 hCol 'As MSHTML.IHTMLElementCollection
    Dim hInp 'As MSHTML.HTMLInputElement
    Dim hSub 'As MSHTML.HTMLInputButtonElement
    Dim hTxt 'As MSHTML.HTMLInputTextElement

    Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

    Private Sub Command1_Click()
    Dim iStart As Integer
    Dim iEnd As Integer
    iStart = 0
    iEnd = 0
    If WebBrowser1.LocationURL <> "http://www.upcdatabase.com/nocheckdigit.pl" Then
    WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl"
    End If
    Do While WebBrowser1.Busy = True
    DoEvents
    Sleep 500
    Loop
    Set hDoc = WebBrowser1.Document
    Set hInp = hDoc.getElementById("upc")
    hInp.focus
    hInp.Value = "07800008846"
    SendKeys "{ENTER}", True
    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)
    '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)
    '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)
    '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)
    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
    Attached Files Attached Files
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  9. #49
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I need to get data form a web page

    From post 36. you need to add this reference and control.
    VB Code:
    1. 'Add reference to Microsoft HTML Object Library
    2. 'Add component Microsoft Internet Controls
    What error are you getting?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #50

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry Re: I need to get data form a web page

    I can run moor then one time.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  11. #51
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I need to get data form a web page

    Come on Bob, you got to give some effort and write at least one line of code.
    You didnt even state if your getting an error or what you are wanting to do?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #52

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry Re: I need to get data form a web page

    I not know vb 6.0 at all.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  13. #53
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I need to get data form a web page

    I think the isue is that the page is not completely loaded when the hInp object is trying to get set.
    Try adding thevaders sggestion.

    VB Code:
    1. Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    2.     DoEvents
    3. Loop
    Instead of this one.
    VB Code:
    1. Do While WebBrowser1.Busy = True
    2.     DoEvents
    3.     Sleep 500
    4. Loop
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #54
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    I tried his suggestions. The ready state fires too soon for the first messagebox, so I had to leave the sleep command in. I also couldn't get the .click to work either. Here is what I have to get them automatically.
    And added the error trap in case you have an invalid number.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim iStart As Integer
    3.     Dim iEnd As Integer
    4.     Dim UPC As String
    5.     iStart = 0
    6.     iEnd = 0
    7.     If WebBrowser1.LocationURL <> "http://www.upcdatabase.com/nocheckdigit.pl" Then
    8.         WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl"
    9.     End If
    10.     Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    11.         DoEvents
    12.     Loop
    13.     Set hDoc = WebBrowser1.Document
    14.     Set hInp = hDoc.getElementById("upc")
    15.     UPC = InputBox("Enter UPC Number", , "07800008846")
    16.     hInp.focus
    17.     hInp.Value = UPC
    18.     SendKeys "{ENTER}", True
    19.     Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    20.         DoEvents
    21.         Sleep 500
    22.     Loop
    23.     Set hInp = Nothing
    24.     'Parse the elements and read the values of the data returned
    25.     'Set document variable = to the new results documents page
    26.     On Error GoTo error_not_found
    27.     Set hDoc = WebBrowser1.Document
    28.     'Find the description:
    29.     iStart = InStr(1, hDoc.body.innerHTML, "<TD>Description</TD>") + 37
    30.     iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>")
    31.     MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
    32.     'Find the Size/Weight:
    33.     iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Size/Weight</TD>") + 37
    34.     iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>")
    35.     MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
    36.     'Find Manufacturer:
    37.     iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Manufacturer</TD>") + 38
    38.     iEnd = InStr(iStart, hDoc.body.innerHTML, "(<A href=")
    39.     MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
    40.     'Find the Entered/Modified:
    41.     iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Entered/Modified</TD>") + 42
    42.     iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>")
    43.     MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart)
    44. error_not_found:
    45.      On Error GoTo 0
    46.      WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl"
    47. End Sub

  15. #55

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry Re: I need to get data form a web page

    how do I save it in dat formet upc.dat
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  16. #56
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: I need to get data form a web page

    Attached is a sample project that completely relies on the Document Object Model to extract the info from the UPC site. It's much more reliable than string parsing, and needs fewer lines too. I'll write another example to play around with VBForums, David.

    Bob, why do you attempt to write an application in a programming language you don't know and obviously do not want to learn? If you want an application written for you, hire a programmer at RentACoder.com. A forum is meant to help you with programming, not to deliver complete applications for free on demand...
    Attached Files Attached Files
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  17. #57
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    using that, I still get an object or with block not set. I think the same thing was happening when I switched my example back to the sleep statement. The error is on the line that submits the upc number. If I hit F5, it runs, though.

    That definitely seems like the correct way to do it. Thanks.

  18. #58
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: I need to get data form a web page

    It happens because the loop is entered before the BeforeNavigate2 event has been reached. Try putting 'blnBusy = True' just before the loop; that should solve it.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  19. #59
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    That does it. Thanks.
    Can you interface with ASP with the same method?

  20. #60
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    Quote Originally Posted by bob5371
    Fix the the code.

    You did? Great. I did, too!
    Last edited by dglienna; Mar 25th, 2005 at 07:10 PM.

  21. #61

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry 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.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  22. #62
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: I need to get data form a web page

    VB Code:
    1. Option Explicit
    2. Dim UPC As String
    3. Dim blnBusy As Boolean
    4. dim field as string
    5. dim ff as integer
    6. dim lfield as integer
    7. open app.path & "bob.dat" for APPEND as #ff
    8. '
    9. '  use the old code up to here
    10. '
    11. For i = 0 To WebBrowser1.Document.getElementsByTagName("td").length - 1
    12.     Select Case WebBrowser1.Document.getElementsByTagName("td").Item(i).innerText
    13.         lfield=0
    14.         Case "Description"
    15.            ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
    16.           lfield = 1
    17.         case "Size/Weight"
    18.            ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
    19.           lfield = 1
    20.         case "Manufacturer"
    21.            ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
    22.           lfield = 1
    23.         case "Entered/Modified"
    24.            ifield = WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
    25.           lfield= 2
    26.     End Select
    27.     if lfield = 1
    28.         print #ff, chr$(34) & ifield & chr$(34) & ", " ;
    29.       elseif
    30.         if lfield=2
    31.           print #ff, chr$(34) & ifield & chr$(34)
    32.       endif
    33. Next i
    34. close #ff
    35. End Sub

    this should be the way that you want to do it.

  23. #63

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry Re: I need to get data form a web page

    can you all fix the code for me.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  24. #64

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry Re: I need to get data form a web page

    can you all help me get fix.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  25. #65
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  26. #66
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,942

    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:
    1. Option Explicit
    2. 'Add component to Microsoft HTML Object Library
    3. 'Add component Microsoft Internet Controls
    4.  
    5. 'Add a command button (Command1)
    6. 'Add a web browser control to the form (WebBrowser1)
    7. Dim hDoc As MSHTML.HTMLDocument
    8. Dim hInp As MSHTML.HTMLInputElement
    9.  
    10. Private Sub Command1_Click()
    11.     Set hInp = hDoc.getElementById("upc")
    12.     hInp.focus
    13.     hInp.Value = "07800008846"
    14.     SendKeys "{ENTER}", True
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18.     WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl"
    19. End Sub
    20.  
    21. Private Sub Form_Resize()
    22.     If Me.WindowState <> vbMinimized Then
    23.         WebBrowser1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight - 450 'Make adjustment for command button
    24.     End If
    25. End Sub
    26.  
    27. Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    28.     Set hDoc = WebBrowser1.Document
    29. End Sub
    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.

  27. #67
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    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
    Last edited by Frans C; Jun 16th, 2005 at 07:04 AM.
    Frans

  28. #68
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: I need to get data form a web page

    Quote Originally Posted by Frans C
    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
    But Frans, where would be the learning experience in doing that.
    We want to write allot of code and use different techniques. Jk

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  29. #69
    Junior Member
    Join Date
    Jul 2006
    Posts
    23

    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:
    1. Option Explicit
    2.  
    3. Dim blnBusy As Boolean
    4.  
    5. Private Sub Command1_Click()
    6. Dim i As Integer
    7.  
    8.  
    9. 'set this so the loop doesnt enter to quickly
    10. blnBusy = True
    11.  
    12. 'load went here
    13. 'Navigate to the page
    14. WebBrowser1.Navigate2 "http://www.onestopmotors.com/admin"
    15.  
    16. 'Both the readystate and the busy properties of the WB control
    17. 'are not completely reliable. The best way to wait for loading to take
    18. 'place I have found so far is using a custom boolean variable that
    19. 'is set in the BeforeNavigate2 and NavigateComplete2 events.
    20. Do While blnBusy = True
    21.     DoEvents
    22. Loop
    23.  
    24. 'Fill in the textboxs with user and pwd
    25. WebBrowser1.Document.getElementById("txtUser").Value = "jason"
    26. WebBrowser1.Document.getElementById("txtPwd").Value = "wopper"
    27. WebBrowser1.Document.All.btnLogin.Click
    28.  
    29. 'Submit went here
    30.  
    31. 'Wait for the new page to load again
    32. Do While blnBusy = True
    33.     DoEvents
    34. Loop
    35.  
    36. 'Enumerate all TD tags in the document, because the info we want to extract
    37. 'is inside them.
    38. For i = 0 To WebBrowser1.Document.getElementsByTagName("td").length - 1
    39.     Select Case WebBrowser1.Document.getElementsByTagName("td").Item(i).innerText
    40.         'If the text of the TD tag is one of the value names we're
    41.         'looking for, return the text in the second TD tag after it.
    42.         'As you can see in the source, all TD's with value names are
    43.         'followed by an empty TD tag and a TD tag containing the actual
    44.         'value. E.g. <td>Description</td><td></td><td>DR PEPPER CHER VAN 2LT</td>
    45.         Case "Description", "Size/Weight", "Manufacturer", "Entered/Modified"
    46.             MsgBox WebBrowser1.Document.getElementsByTagName("td").Item(i + 2).innerText
    47.     End Select
    48. Next i
    49. End Sub
    50.  
    51. Private Sub Command2_Click()
    52.  
    53. 'Navigate to the page
    54. WebBrowser1.Navigate2 "http://www.onestopmotors.com/admin"
    55.  
    56.  
    57. End Sub
    58.  
    59.  
    60. Private Sub Command3_Click()
    61. WebBrowser1.Document.getElementById("txtsearch").Value = Text1.Text
    62. WebBrowser1.Document.All.btnSearch.Click
    63. End Sub
    64.  
    65. 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)
    66. blnBusy = True
    67. End Sub
    68.  
    69. Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    70. blnBusy = False
    71. End Sub

  30. #70

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry 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.
    Attached Files Attached Files
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  31. #71
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: I need to get data form a web page

    Quote Originally Posted by Frans C
    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
    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.

  32. #72

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Re: I need to get data form a web page

    can you fix it?
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  33. #73
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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?

  34. #74

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry 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.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  35. #75
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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

  36. #76

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Re: I need to get data form a web page

    the page have update then.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  37. #77

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    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 ?
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  38. #78
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: I need to get data form a web page

    I get RESOURCE NOT FOUND when I click your link Bob.

  39. #79

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    Angry Re: I need to get data form a web page

    RobDog888 give the link.
    Last edited by bob5731; Apr 11th, 2008 at 01:53 PM.
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

  40. #80

    Thread Starter
    Fanatic Member bob5731's Avatar
    Join Date
    Nov 2004
    Posts
    918

    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
    Attached Files Attached Files
    P.S. God Love You And Have A Good Day!!!My web page

    I need to get a free Iphone

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width