Results 1 to 13 of 13

Thread: Read web page dynamically (Solved)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Resolved Read web page dynamically (Solved)

    Hi

    I want to read some texts from a web page dynamially using VB6. This text is not same string every time, it is like a secret code subjected to change on each visit to this page.

    I was reading by tagname like:
    Code:
    Dim MySecretCode as String
    MySecretCode  = WebBrowser1.Document.getElementsByTagName("td").Item(4).innerText
    But whenever any modification occures in the webpage the item number 18 is changed so I want to findout the correct number and change this in my code or in database for every modification in the webpage

    So is there any trick to read the required text dynamically.

    In the web page there is a constant text in a cell before the cell of the secret code that I need to read.

    If it is possible to find out the item number of a cell based on the text in it, I think I can solve my problem, but I don't know how to find the item number dynamically

    I hope anybody can help me

    With regards,
    Nasreen
    Last edited by nasreen; Dec 24th, 2008 at 01:24 AM. Reason: Solved

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Read web page dynamically

    How about INSTR? Is the table containing that item is dynamically being changed also? If not perhaps you could instead retrieve it and then just retrieve on what column the data you want is located.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Read web page dynamically

    Hi dee-u
    In my case the INSTR is not applicable because the data is changed and once every two month some columns and rows in the tables also either added or removed due to modifications in the page. So that I cannot depend a constact item number of the cell.
    As I think the possible way is what did you say:
    If not perhaps you could instead retrieve it and then just retrieve on what column the data you want is located.
    Because there is another cell with a static data in it and this cell is adjacent for the cell I want read it. We can read this static data with INSTR and if possible we can find out the item number of this cell

    But I don't know how to retrieve a column or cell item number based on the data in it.

    Can anybody forward me a solution ?

    With regards,
    Nasreen
    Last edited by nasreen; Dec 19th, 2008 at 03:24 AM.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Read web page dynamically

    it is probably quite easy to do, but i would need to look at the web page
    can you post a link to it, or pm it to me
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Read web page dynamically

    Hi westconn1

    Here I attached the saved page of my webpage (confirm.zip). The value I want to read formt this page is (585564559854564), and it is not constant but is changed upon every visit to this page. The text(U Code: ) is constant.

    With regards,
    Nasreen
    Attached Files Attached Files
    Last edited by nasreen; Dec 19th, 2008 at 10:16 AM.

  6. #6
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Read web page dynamically

    Can't you just simply modify the code that generates the html output, to add id= property to each td element? Just like

    Code:
    <td id="td:12_3">value here</td><td id="td:12_4">value here</td>.. etc The 12 can be a row, and 4 can be a column identifier.
    So you can get these element by their id anytime you are looking for its value.

    document.getElementById('td:12_3').innerText
    document.getElementById('td:12_4').innerText

    Its just a tip, havent tested, but you might want to.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Read web page dynamically

    Hi Jim Davis
    Thanks for your replay.
    Please be informed that I have no any control on the web page since it is for a third party in a western country. Our company uses the services of this website and I am assigned to develop a project to store the data of the page in the local server of our company.
    The web page is subjected to modification oftenly that changes positions of rows and columns of the tables in it. So I cannot depend a constant item number of the cell.
    What I expect is an idea to find out the item number of a cell holds a constant value. In my attached page it is U Code:. So this item number + 1 will be the accurate item number of the cell that I want to read exactly. We can find out this constant value using INSTR, but how we can find out the item number of that cell or any other solution to get the exact value

    With regards,
    Nasreen

  8. #8
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Read web page dynamically

    Since the ucode is encapusalted between <span> tags,

    WebBrowser1.Document.getElementsByTagName("span").innerText

    or

    WebBrowser1.Document.getElementsByTagName("span").Item(0 /or 1/).innerText

    should work.

  9. #9
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Read web page dynamically

    This will parse out the td tag after the tag containing U Case as it's text
    Code:
    Private Sub Command1_Click()
    Dim strURL As String
    Dim objHTML
    Dim intPos As Integer
    Dim strHTML As String
    
    
        strURL = "C:\Documents and Settings\Mark\Desktop\Confirm\Confirm.htm"
        Set objHTML = CreateObject("Microsoft.XMLHTTP")
        objHTML.open "GET", strURL, False
        objHTML.send
        
        strHTML = objHTML.responseText
        Set objHTML = Nothing
        
        
        'Find the U Code text and remove everything before it
        intPos = InStr(strHTML, "U Code")
        strHTML = Mid(strHTML, intPos)
        
        'Find the next td tag. This will hold the data you are after
        intPos = InStr(strHTML, "<td")
        strHTML = Mid(strHTML, intPos)
        
        'Find the closing td tag and remove everything after it
        intPos = InStr(strHTML, "</td>") + 4
        strHTML = Left(strHTML, intPos)
        
        'strip off everything after the value
        intPos = InStr(strHTML, "</") - 1
        strHTML = Left(strHTML, intPos)
        
        'remove everything before your value
        intPos = InStrRev(strHTML, ">") + 1
        strHTML = Mid(strHTML, intPos)
        
        'this should be the value you are looking for
        Text1.Text = strHTML
        
    End Sub
    EDIT: Finished the example
    Last edited by MarkT; Dec 19th, 2008 at 03:06 PM.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Read web page dynamically

    you can try this,
    MsgBox web1.document.All("ms__id6").innerText
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Read web page dynamically

    Thanks Mr. MarkT

    Your idea is almost OK and is a solution for an extend.

    For this web page it is good and working fine. My company is dealing with a number of services like this using different online money transfer web services. I don't know how far I can apply this idea for each web pages..

    If I get an idea to find out the item number of the cell it will be the best solution for my problem

    Code:
    MsgBox web1.document.All("ms__id6").innerText
    This code is not working with me. Can I know what is this ("ms__id6") ??

    With regards
    Nasreen
    Last edited by nasreen; Dec 20th, 2008 at 09:11 AM.

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Read web page dynamically

    unique id for that element, it returned the correct value for me

    it should remain constant unless the page is redesigned

    you can try like this
    vb Code:
    1. For Each ele In ie.Document.getelementsbytagname("Span")
    2.  MsgBox ele.innertext
    3.  Next
    Last edited by westconn1; Dec 20th, 2008 at 05:16 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Resolved Re: Read web page dynamically (Solved)

    Hi all,
    Finally I got the idea that I look for. I would like to share with all

    Code:
    Private Sub Form_Load()
    WebBrowser1.Navigate2 App.Path & "\Confirm.htm"
    End Sub
    
    Private Sub Command1_Click()
    Dim ii As Integer
    Dim docEl
    Dim Ucode As String
    
     For Each docEl In WebBrowser1.Document.documentElement.All
            If docEl.tagName = "TR" Then
                For ii = 0 To docEl.Cells.Length - 1
                        If UCase(Trim(docEl.Cells(ii).innerText)) = UCase("Ucode:") Then
                            Ucode= Trim(docEl.Cells(ii + 1).innerText)
                        End If
                Next
            End If
        Next
        Text1.Text = Ucode
    End Sub
    With regards,
    Nasreen

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