-
Get Information off a page
This kind of branches of my other post, but has one same thing I need to know.
1st: I need to know how to figure out what page I am on in my browser (A browser I made from Browser control)
2nd: How to get information off a page. Like certian information. For the page I am on, there are lists of links, and each link has its own info. Like it will be (Link)>(Item Price)>(Item Quanity). And there will be several rows of links that have that same order. I need to get the Item Price part. How do I search the page, or somehow get this information.
-
Re: Get Information off a page
1. Will the LocationURL help?
2. Will .getElementsByTagName help?
-
Re: Get Information off a page
Well, nevermind the first one. I got that figured out. The second one, its just plain text. I dont think its really an element.
-
Re: Get Information off a page
Perhaps you could post part of the html source where the information you need is located?
-
Re: Get Information off a page
That I dont know of. Since I can barely read Html, I cant pick out the part of the source. Also, It wont be the same source everytime. What I am getting info off of is a search engine basicly. So, the results vary, and will always be different.
-
Re: Get Information off a page
You could just right click a certain webpage then there will be a View Page Source option, if you will click it then the source of the webpage you are viewing will be shown in notepad...
-
1 Attachment(s)
Re: Get Information off a page
Yea, I know that. I just ment I cant pick out the part I need of the source. Because you wanted the part. Well, here is the full source attached. Remember this is just one result, it can vary.
-
Re: Get Information off a page
So, is there another way? Looking at the source, theres not much about the table and the parts of it. Like I said its Link>Price>Quanity and I need price. I know it is possible, because I have seen other programs do it before. Made with Vb6 too. So there has to be a way.
-
Re: Get Information off a page
Could you provide the link you want? Will the link be constant or will it change? You mean you will click/navigate to the link then retrieve the item price and quantity?
-
Re: Get Information off a page
I cant give the link. Its one of those things where the link never changes even if you search for something different. So say you search for something and you get your results on the page "www.site.com/results" then you do another and get your results on "www.site.com/results". So no matter what the link stays the same. My program enters the information and submits it, and gets to the results page, and now I want it to retrieve the item price thats all.
-
Re: Get Information off a page
As I have examined the source you attached I've found out that the data you need are in a table cell, you could try locating them.... :thumb:
-
Re: Get Information off a page
oo my head hurts now lol. I dont see it. Is it labled "the table"? I have not read Html in a loong time. I cant find the table though, I found the toolbar and topbar, but not the actual table with the results. Could you excuse me this time :D
-
Re: Get Information off a page
From looking at the html source code you provided I came up with two methods which should work...Personally I'd probably go with using a RegExp but since most VB coders aren't comfortable with RegExps I'll outline the other.
I assume you have the full source in a string variable - I'll call that htmlStr for this example.
VB Code:
Dim strParts() As String, i As Integar, j As Integar, itemPrice As String
strParts = Split(htmlStr,"</b></td></tr>")
' strParts(0) will contain all of the syle sheeting, scripts, etc,
' throught the first row of the table so just ignore it
for i = 1 to Ubound(strParts)
If Instr(strParts(i),"item you are looking for goes here") then
j = InstrRev(strParts(i),">")
itemPrice = Mid$(strParts(i), j)
Exit For
End IF
next i
That should provide you with an itemPrice string like "44,500 NP". Of course, if you're wanting to capture the price for multiple items you would need to modify that code accordingly..
-
2 Attachment(s)
Re: Get Information off a page
Is these what you are looking? I have attached the parsed code....
-
Re: Get Information off a page
Alright here is my coding:
VB Code:
Private Sub cmdPrice_Click()
Load Browser
Browser.Show
Dim itm As ListItem
Set itm = ListView1.SelectedItem
Browser.WebMain.Navigate "http://www.neopets.com/market.phtml?type=wizard"
Do Until Not Browser.WebMain.Busy
DoEvents
Loop
'Alright, the above loop waits for the page to be done loading. Otherwise we can't examine the HTML
Dim doc As IHTMLDocument2
Dim element As IHTMLElement
Dim inp As IHTMLInputElement
Dim j As Integer, s As String
Set doc = Browser.WebMain.Document 'Making the doc variable reference the web browser document; in other words, when doc is used, read it as web.Document.
For j = 0 To doc.All.length - 1
'we'll loop through all tags in the HTML to see if it is one of the input boxes.
Set element = doc.All.Item(j)
If element.tagName = "INPUT" Then
'if the tag of the selected element is INPUT, then it may be a textbox.
Set inp = element
Select Case inp.Name
Case "shopwizard": inp.Value = itm.Text
Case "min_price": inp.Value = "0"
Case "max_price": inp.Value = ""
End Select
'if the name of the element (the 'name' attribute) is 'shopwizard', it's the textbox we're looking for.
End If
Next j
For j = 0 To doc.All.length - 1 ' This submits our data and brings us to the results page.
Set element = doc.All.Item(j)
If element.tagName = "INPUT" Then
Set inp = element
If inp.Name = "" Then
inp.Click
End If
End If
Next j
HtmlStr = "C:\Source.txt"
Dim strParts() As String, i As Integer, j1 As Integer, itemPrice As String
strParts = Split(HtmlStr, "</b></td></tr>")
For i = 1 To UBound(strParts)
If InStr(strParts(i), itm.Text) Then
j1 = InStrRev(strParts(i), ">")
itemPrice = Mid$(strParts(i), j1)
Exit For
End If
Next i
MsgBox itemPrice
End Sub
That should search for the item the user specified, then got the price of the item. Its no working. Also, I wanted the price of the first item on the list. Only the first one and no others. I dont think that coding is doing that. Can I do that?
-
Re: Get Information off a page
Ok, I see what you were trying to do. See, I dont need to search for the item. The item is same, its just different shops that have that item. It goes by cheapest from first to last. I need the cheapest price, so I need the first items price. Searching would not do anything, that explains it I think.
-
Re: Get Information off a page
couldnt you use the same code i gave you yesterday?
-
Re: Get Information off a page
Which would be? Sorry, I get alot of coding, hard to keep track of what I get. I thought yours didn't work or something. Could you repost it?
-
Re: Get Information off a page
Assuming all of the code prior to what I just gave you works as desired, change your code to this and see if that does the trick.
VB Code:
Private Sub cmdPrice_Click()
Load Browser
Browser.Show
Dim itm As ListItem
Set itm = ListView1.SelectedItem
Browser.WebMain.Navigate "http://www.neopets.com/market.phtml?type=wizard"
Do Until Not Browser.WebMain.Busy
DoEvents
Loop
'Alright, the above loop waits for the page to be done loading. Otherwise we can't examine the HTML
Dim doc As IHTMLDocument2
Dim element As IHTMLElement
Dim inp As IHTMLInputElement
Dim j As Integer, s As String
Set doc = Browser.WebMain.Document 'Making the doc variable reference the web browser document; in other words, when doc is used, read it as web.Document.
For j = 0 To doc.All.length - 1
'we'll loop through all tags in the HTML to see if it is one of the input boxes.
Set element = doc.All.Item(j)
If element.tagName = "INPUT" Then
'if the tag of the selected element is INPUT, then it may be a textbox.
Set inp = element
Select Case inp.Name
Case "shopwizard": inp.Value = itm.Text
Case "min_price": inp.Value = "0"
Case "max_price": inp.Value = ""
End Select
'if the name of the element (the 'name' attribute) is 'shopwizard', it's the textbox we're looking for.
End If
Next j
For j = 0 To doc.All.length - 1 ' This submits our data and brings us to the results page.
Set element = doc.All.Item(j)
If element.tagName = "INPUT" Then
Set inp = element
If inp.Name = "" Then
inp.Click
End If
End If
Next j
Do Until Not Browser.WebMain.Busy
DoEvents
Loop
doc = Browser.WebMain.Document
Dim strParts() As String, itemPrice As String, i as Integer
strParts = Split(doc, "</b></td></tr>")
i = InStrRev(strParts(1), ">")
itemPrice = Mid$(strParts(1), i)
MsgBox itemPrice
End Sub
-
Re: Get Information off a page
Im getting an error with:
"doc = Browser.WebMain.Document"
Saying the object does not support that method. So thats not a browser control. Mistake?
-
Re: Get Information off a page
Spending some minutes locating the data you need I came up with this, take a look if its correct!
VB Code:
Dim oDoc As HTMLDocument
Dim oCell As HTMLTableCell
Set oDoc = WebMain.Document
Set oCell = oDoc.getElementsByTagName("td")(20)
MsgBox oCell.innerText
-
Re: Get Information off a page
dee-u, the messagebox gave me "NP ". Im assuming there was supposed to be an amount in there. The first item in the list was 100,000. So shouldn't it have been "NP 100,000"?
-
Re: Get Information off a page
i actually have no idea where the code is. It found all the links you were looking for on a page, even though they change.
-
Re: Get Information off a page
Well, in the thread where I asked how to get the the first link or certian link you said you could not help me.
Found the thread:
http://www.vbforums.com/showthread.php?t=344522
-
Re: Get Information off a page
Fiddle with it...
VB Code:
Set oCell = oDoc.getElementsByTagName("td")(19)
MsgBox oCell.innerText
MsgBox oCell.innerHTML
VB Code:
Set oCell = oDoc.getElementsByTagName("td")(21)
MsgBox oCell.innerText
MsgBox oCell.innerHTML
I noticed, you are using interface (IHTMLDocument2), try using HTMLDocument, also in your other declarations... ;)
-
Re: Get Information off a page
what do you mean i couldnt help you??? did you even try the code i posted???
-
Re: Get Information off a page
Yes, I did, it wont work because I cant specify the url. Remember how I said all that stuff about the link being the same no matter what, so I cant simple go like
x = Inet1.OpenURL("http://www.neopets.com/market.phtml", icString)
Thats why it didn't work. Then after that you said you couldn't help me with it anymore.
-
Re: Get Information off a page
Ok, dee-u I kinda got your code working, except I cant use it for two reasons. It is definantly not reliable, as for some reason the vaule will change in odd patterns like sometimes it will be correct and be like "200 NP", other times it will be like "NP ", and "Optional". All those weird results.
Second reason, I only need numbers, not numbers then NP like "320 NP". So unless I can make it fit around these two standards, I need another way.
-
Re: Get Information off a page
What you may do is to list all tables and determine if it has Shop Owner, Item, Amount in Stock and Price table cells and go from there... Sorry I have got no time to code it for you....
To parse the Price only you could use Replace to replace NP with empty string....
-
Re: Get Information off a page
Yea, I gotts go as well, does someone else have the time to code what dee-u is talking about for me?
-
Re: Get Information off a page
Alright, so how do I replace the "NP" in it? And, could you explain a litte more, Im not sure I know how to do what your talking about in the first part.
-
Re: Get Information off a page
x = replace(string with NP in it here,"NP",vbnullstring)
-
Re: Get Information off a page
Dim x As Variant
x = Replace(Cprice, "NP", vbNullString)
Not working, still got "NP " In the messagebox.
-
Re: Get Information off a page
Cprice = Replace(Cprice, "NP", vbNullString)
-
Re: Get Information off a page
omg, duh forgot about that part. Anyways, |2eM!X did you have a way? Because I am getting some serious problems with dee-u's. Now I am getting blank every time in the message box. I might have messed up the coding but here is what I have now:
VB Code:
Private Sub cmdPrice_Click()
Dim Loc As String
Loc = InputBox("What position is the item? (Starting from the first item as 1)")
Load Browser
Browser.Show
Dim itm As ListItem
Set itm = ListView1.SelectedItem
Browser.WebMain.Navigate "http://www.neopets.com/market.phtml?type=wizard"
Do Until Not Browser.WebMain.Busy
DoEvents
Loop
'Alright, the above loop waits for the page to be done loading. Otherwise we can't examine the HTML
Dim doc As IHTMLDocument2
Dim element As IHTMLElement
Dim inp As IHTMLInputElement
Dim j As Integer, s As String
Set doc = Browser.WebMain.Document 'Making the doc variable reference the web browser document; in other words, when doc is used, read it as web.Document.
For j = 0 To doc.All.length - 1
'we'll loop through all tags in the HTML to see if it is one of the input boxes.
Set element = doc.All.Item(j)
If element.tagName = "INPUT" Then
'if the tag of the selected element is INPUT, then it may be a textbox.
Set inp = element
Select Case inp.Name
Case "shopwizard": inp.Value = itm.Text
Case "min_price": inp.Value = "0"
Case "max_price": inp.Value = ""
End Select
'if the name of the element (the 'name' attribute) is 'shopwizard', it's the textbox we're looking for.
End If
Next j
For j = 0 To doc.All.length - 1
Set element = doc.All.Item(j)
If element.tagName = "INPUT" Then
Set inp = element
If inp.Name = "" Then
inp.Click
End If
End If
Next j
Do Until Browser.WebMain.Busy
DoEvents
Loop
HtmlStr = "C:\Source.txt"
Dim oDoc As HTMLDocument
Dim oCell As HTMLTableCell
Set oDoc = Browser.WebMain.Document
Set oCell = oDoc.getElementsByTagName("td")(20)
Dim Cprice As String
Cprice = oCell.innerText
Cprice = Replace(Cprice, "NP", vbNullString)
Browser.WebMain.Navigate "http://www.neopets.com/market.phtml?type=your"
Do Until Not Browser.WebMain.Busy
DoEvents
Loop
Set doc = Browser.WebMain.Document
For j = 0 To doc.All.length - 1
'we'll loop through all tags in the HTML to see if it is one of the input boxes.
Set element = doc.All.Item(j)
If element.tagName = "INPUT" Then
'if the tag of the selected element is INPUT, then it may be a textbox.
Set inp = element
If inp.Name = "cost_" & Loc Then
inp.Value = Cprice
'if the name of the element (the 'name' attribute) is 'shopwizard', it's the textbox we're looking for.
End If
End If
Next j
MsgBox Cprice
End Sub
That should search find the price, and price the item on the pricing page. Except, now I am getting nothing for the item price, on rare occasions ill get a number, but it has not been doing it lately. Which is not good, because I plan on releasing this to people. So is there something wrong? Or another way?