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
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",)
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.
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
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
Last edited by nasreen; Dec 19th, 2008 at 10:16 AM.
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
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
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
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.
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:
For Each ele In ie.Document.getelementsbytagname("Span")
MsgBox ele.innertext
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
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