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.
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.
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...
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
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.
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.
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?
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
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.
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
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..
'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?
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.
'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
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"?
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.
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.
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....
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
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.
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)")
'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.
'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?