|
-
Jun 30th, 2006, 01:48 PM
#1
Thread Starter
Hyperactive Member
Grab Html Source
My program grabs the html source, and I'm not sure how to seperate it enough just to get a certain part.. here is a section of the HTML..
HTML Code:
<tr>
<td align=right>
<font face=arial size="-1">AS DA:</font></td>
<td><font face=arial size="-1"><b>John</b></font>
</td>
</tr>
In the source of the entire page, there are many things like
HTML Code:
<font face=arial size="-1">
I want to know how to find the John part somehow using the part to get it. Thanks for any help.
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 02:04 PM
#2
Thread Starter
Hyperactive Member
Re: Grab Html Source
Any help with this? Anything is greatly appreciated
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 02:20 PM
#3
Fanatic Member
Re: Grab Html Source
If you want to find the text that is in the place of 'John', you could use this
VB Code:
Private Function FindName(HTML As String) As String
Dim StartPt As Integer, EndPt As Integer
StartPt = Instr(1, HTML, "AS DA:</font></td>" & vbNewLine & "<td><font face=arial size=" & Chr(34) & "-1" & Chr(34) & "><b>")
EndPt = Instr(StartPt, HTML, "</b></font>") - StartPt
FindName = Mid$(HTML, StartPt, EndPt)
End Function
Just call FindName() with the HTML source and it will return the name!
Plz add to my reputation if this helped!
-
Jun 30th, 2006, 02:27 PM
#4
Thread Starter
Hyperactive Member
Re: Grab Html Source
Well, I'm not quite sure how to use this.. Maybe you can add in where i should put this and how.. or maybe just show me a simple source that downloads the html and includes that? Thanks..
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 02:33 PM
#5
Junior Member
Re: Grab Html Source
You could use the Split command to seperate it into sections...
-
Jun 30th, 2006, 02:36 PM
#6
Re: Grab Html Source
what are you tring to do... explain what you want the end result to be.
how are you getting the source? inet? webbrowser? html object?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 30th, 2006, 02:38 PM
#7
Fanatic Member
Re: Grab Html Source
I provided you with a function that parses out the name from the HTML.
You can use the Inet control to download the HTML source code and then send it to the FindName function which will return the name in the HTML.
Add the Microsoft Internet Transfer Control to your components (CTRL + T) and then use this code when you have a command button named Command1 and an Inet control named Inet1 on your form
VB Code:
Private Sub Command1_Click()
Dim htmlName As String
htmlName = FindName(Inet1.OpenURL("http://www.MY-URL-HERE.com"))
MsgBox htmlName, vbInformation
End Sub
Private Function FindName(HTML As String) As String
Dim StartPt As Integer, EndPt As Integer
StartPt = Instr(1, HTML, "AS DA:</font></td>" & vbNewLine & "<td><font face=arial size=" & Chr(34) & "-1" & Chr(34) & "><b>")
EndPt = Instr(StartPt, HTML, "</b></font>") - StartPt
FindName = Mid$(HTML, StartPt, EndPt)
End Function
This will connect to the website and then parse out the name contained in the HTML and display it in a message box
Last edited by shirazamod; Jun 30th, 2006 at 02:41 PM.
-
Jun 30th, 2006, 02:49 PM
#8
Thread Starter
Hyperactive Member
Re: Grab Html Source
I tried doing what you said and all it does is highlight
htmlName = FindName(Inet1.OpenURL("http://www.MY-URL-HERE.com"))
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 02:50 PM
#9
Thread Starter
Hyperactive Member
Re: Grab Html Source
oh, nevermind that was dumb of me. I never put Inet on the form.
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 02:52 PM
#10
Thread Starter
Hyperactive Member
Re: Grab Html Source
I tried again and all it does is wait a few seconds and then says Type Mismatch and highlights this line
htmlName = FindName(Inet1.OpenURL("http://www.MY-URL-HERE.com"))
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 02:52 PM
#11
Fanatic Member
Re: Grab Html Source
You need to replace "MY-URL-HERE" with the URL to the page that you want to get the HTML from.
If it works, please mark this thread Resolved & add to my reputation!!
-
Jun 30th, 2006, 02:56 PM
#12
Thread Starter
Hyperactive Member
Re: Grab Html Source
Yes, i already did replace that But i still get the error 'Type Mismatch'
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 02:59 PM
#13
Fanatic Member
Re: Grab Html Source
Please edit the code so that the first line of the FindName() function isAnd then post what the HTML is so that we can help
-
Jun 30th, 2006, 03:04 PM
#14
Thread Starter
Hyperactive Member
Re: Grab Html Source
VB Code:
Private Sub Command1_Click()
Dim htmlName As String
Debug.Print HTML
htmlName = FindName(Inet1.OpenURL("http://www.MY-URL-HERE.com"))
MsgBox htmlName, vbInformation
End Sub
Private Function FindName(HTML As String) As String
Dim StartPt As Integer, EndPt As Integer
StartPt = Instr(1, HTML, "AS DA:</font></td>" & vbNewLine & "<td><font face=arial size=" & Chr(34) & "-1" & Chr(34) & "><b>")
EndPt = Instr(StartPt, HTML, "</b></font>") - StartPt
FindName = Mid$(HTML, StartPt, EndPt)
End Function
Like that?
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 03:05 PM
#15
Thread Starter
Hyperactive Member
Re: Grab Html Source
VB Code:
Private Sub Command1_Click()
Dim htmlName As String
htmlName = FindName(Inet1.OpenURL("http://www.MY-URL-HERE.com"))
MsgBox htmlName, vbInformation
End Sub
Private Function FindName(HTML As String) As String
Debug.Print HTML
Dim StartPt As Integer, EndPt As Integer
StartPt = Instr(1, HTML, "AS DA:</font></td>" & vbNewLine & "<td><font face=arial size=" & Chr(34) & "-1" & Chr(34) & "><b>")
EndPt = Instr(StartPt, HTML, "</b></font>") - StartPt
FindName = Mid$(HTML, StartPt, EndPt)
End Function
I tried putting it there also and it didn't make a difference..
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 03:06 PM
#16
Fanatic Member
Re: Grab Html Source
Like this, and then come back here and tell me what it printed:
VB Code:
Private Sub Command1_Click()
Dim htmlName As String
htmlName = FindName(Inet1.OpenURL("http://www.MY-URL-HERE.com"))
MsgBox htmlName, vbInformation
End Sub
Private Function FindName(HTML As String) As String
Dim StartPt As Integer, EndPt As Integer
[b]Debug.Print HTML[/b]
StartPt = Instr(1, HTML, "AS DA:</font></td>" & vbNewLine & "<td><font face=arial size=" & Chr(34) & "-1" & Chr(34) & "><b>")
EndPt = Instr(StartPt, HTML, "</b></font>") - StartPt
FindName = Mid$(HTML, StartPt, EndPt)
End Function
-
Jun 30th, 2006, 03:10 PM
#17
Thread Starter
Hyperactive Member
Re: Grab Html Source
All it did was say type mismatch and higlight the same line again..
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 03:12 PM
#18
Fanatic Member
Re: Grab Html Source
ok then use this
VB Code:
Private Sub Command1_Click()
Dim htmlName As String
htmlName = FindName(Inet1.OpenURL("http://www.MY-URL-HERE.com"))
MsgBox htmlName, vbInformation
End Sub
Private Function FindName(HTML As String) As String
Dim StartPt As Integer, EndPt As Integer
Open "C:\DEBUG.txt" For Output As #1
Print #1, HTML
Close #1
StartPt = Instr(1, HTML, "AS DA:</font></td>" & vbNewLine & "<td><font face=arial size=" & Chr(34) & "-1" & Chr(34) & "><b>")
EndPt = Instr(StartPt, HTML, "</b></font>") - StartPt
FindName = Mid$(HTML, StartPt, EndPt)
End Function
And after it gives you the error go to your C:\ drive and look for a file called DEBUG.txt and post the contents of that file here
REMEMBER to change the URL to the one where your file is
-
Jun 30th, 2006, 03:17 PM
#19
Thread Starter
Hyperactive Member
Re: Grab Html Source
It didn't even make the file.
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 03:30 PM
#20
Fanatic Member
Re: Grab Html Source
That's very strange.
Add a breakpoint on the line that contains your URL and then step through the code using F8 to see exactly where the error occurs
-
Jun 30th, 2006, 03:44 PM
#21
Thread Starter
Hyperactive Member
Re: Grab Html Source
Well, your code doesn't seem to work :-// Oh well, I guess..
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 03:52 PM
#22
Fanatic Member
Re: Grab Html Source
You really don't appreciate what I've done.
I've been trying to help you
-
Jun 30th, 2006, 03:54 PM
#23
Thread Starter
Hyperactive Member
Re: Grab Html Source
Yes, I really appreciate that. I've done everything you've said with no result. So, I guess I'm just giving up, as the code seems flawless and there's nowhere else we can take it to. Therefore, I say 'Oh Well'
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 03:54 PM
#24
Re: Grab Html Source
add a reference to the Microsoft HTML Object Library
VB Code:
Dim HTML As New HTMLDocument
Dim tHTML As HTMLDocument
Dim TBL As HTMLTable
Dim ROW As HTMLTableRow
Dim CELL As HTMLTableCell
Dim NextCell As Boolean
HTML = tHTML.createDocumentFromUrl("http://www.URLHERE.com", vbNullString)
Do Until HTML.readyState = "complete"
DoEvents
Loop
For Each TBL In HTML.getElementsByTagName("table")
For Each ROW In TBL.rows
NextCell = False
For Each CELL In ROW.cells
Debug.Print CELL.innerText
'this is just a guess since I cant see full source
If NextCell Then
MsgBox CELL.innerText
NextCell = False
Exit For
End If
If CELL.innerText = "AS DA:" Then
NextCell = True
End If
Next
Next
Next
or.. actually Try this code:
It work a little better.. but read the note in it.. ive never tried it like that..
setting a CELL object using the cell index
VB Code:
Dim HTML As New HTMLDocument
Dim tHTML As HTMLDocument
Dim TBL As HTMLTable
Dim ROW As HTMLTableRow
Dim CELL As HTMLTableCell
Dim CELL2 As HTMLTableCell
HTML = tHTML.createDocumentFromUrl("http://www.URLHERE.com", vbNullString)
Do Until HTML.readyState = "complete"
DoEvents
Loop
For Each TBL In HTML.getElementsByTagName("table")
For Each ROW In TBL.rows
For Each CELL In ROW.cells
Debug.Print CELL.innerText
'this is just a guess since I cant see full source
If CELL.innerText = "AS DA:" Then
'this code here is UNTESTED! lol..
'ive never tried it this way before but it
'might just work....
Set CELL2 = ROW.cells(CELL.cellIndex + 1)
MsgBox CELL2.innerText
Exit For
End If
Next
Next
Next
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 30th, 2006, 04:03 PM
#25
Thread Starter
Hyperactive Member
Re: Grab Html Source
Maybe you could be so kind as to show me an example on where this code can be used.. or a source :-/ or something
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 04:34 PM
#26
PowerPoster
Re: Grab Html Source
try something like this ..
VB Code:
Private Sub Command1_Click()
Dim i As String
i = getHTMLDocument("http://www.mywebsitepage.com")
If Len(i) Then
i = Replace(i, "AS", Chr(&H9F) & "AS")
Call ParseText(i)
'Text1 = i
End If
End Sub
'// ADD SENTENCES TO TEXT BOX
Private Sub ParseText(ByVal myString As String)
Dim sArray() As String
Dim sTemp As String
Dim sLine As String
Dim iLine As Integer
Dim e As Integer
sArray = Split(myString, Chr(&H9F)) ' SPLIT UP THE SENTENCES
iLine = 0
For e = 0 To UBound(sArray) ' LOOP THROUGH EACH ONE
sTemp = Trim$(sArray(e)) ' GET RID OF SPACES AT ENDS
If Len(sTemp) > 0 Then ' IF THERE IS MORE THAN 1 LETTER
iLine = iLine + 1 ' ADD NUMBERS TO LINES
sLine = Left(sTemp, InStr(sTemp, ":"))
If Len(sLine) Then
Text1 = Text1 & "LINE " & iLine & ": " & sLine & vbCrLf
Text1 = Text1 & "RESULTS: " & Replace(sTemp, sLine, "") & vbCrLf & vbCrLf
End If
End If
Next e
End Sub
'// HTMLDOC *** GET TEXT FROM WEB PAGE **** REFERENCE REQUIRED
Private Function getHTMLDocument(ByVal strUrl As String) As String
Dim HTML As New HTMLDocument
Dim DOC As HTMLDocument
Set DOC = HTML.createDocumentFromUrl(strUrl, vbNullString)
Do While DOC.readyState <> "complete"
DoEvents
Loop
getHTMLDocument = DOC.documentElement.innerText
End Function
-
Jun 30th, 2006, 05:02 PM
#27
Thread Starter
Hyperactive Member
Re: Grab Html Source
Ok, all that did was take the text that is actually shown on the web page.. how am i supposed to find the 'John' part?
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 05:08 PM
#28
Thread Starter
Hyperactive Member
Re: Grab Html Source
I'm guessing I do something like this..
If temp(b) = "As Da:" Then temp (b + 1) And List1.AddItem(List1.ListIndex)
I don't know ..
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 06:23 PM
#29
Junior Member
Re: Grab Html Source
Ok...well to find 'John' in that, use this once you have the HTML saved in a String variable. (Let's assume that the variable is called htmlStore, and it's public)
VB Code:
Private Function FindResult()
Dim HolderOne() as String
Dim HolderTwo() as String
Dim Result As String
HolderOne() = Split(htmlStore, " DA:</font></td>
<td><font face=arial size="-1"><b>")
HolderTwo() = Split(HolderOne(1), "</b></font>")
Result = HolderTwo(0)
MsgBox Result
End Function
All this does is VERY SIMPLY find whatever the name is in the HTML. So, here is what you are going to do once you download the HTML using the INET control:
STORE THE HTML IN A PUBLIC STRING NAMED htmlStore
Then, call this function to find whatever the name is in the document.
That's the easy part. If you don't get it then give up.
Rate it if it works!
-
Jun 30th, 2006, 06:33 PM
#30
Thread Starter
Hyperactive Member
Re: Grab Html Source
When you told me to split this...
HolderOne() = Split(htmlStore, " DA:</font></td>
<td><font face=arial size="-1"><b>")
VB won't let you split that, i just pasted it in and it turned RED.
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 06:39 PM
#31
Thread Starter
Hyperactive Member
Re: Grab Html Source
That's the easy part. If you don't get it then give up.
Also, Thanks for the encouragement.
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 06:42 PM
#32
Thread Starter
Hyperactive Member
Re: Grab Html Source
Even when i tried what was used in the first post..
HolderOne() = Split(htmlStore, "Real Name:</font></td>" & vbNewLine & "<td><font face=arial size=" & Chr(34) & "-1" & Chr(34) & "><b>")
It just highlights the HolderTwo line and says subscript out of range.. The easy part eh?
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jul 1st, 2006, 02:07 AM
#33
Fanatic Member
Re: Grab Html Source
You can adapt my 'FindName' function from above to get the 'John' part out of the html
-
Jul 1st, 2006, 01:50 PM
#34
Junior Member
Re: Grab Html Source
VB Code:
Public Sub getName()
On Error Resume Next
'Get the text between search strings.
Dim sSource As String
Dim sFindStart As String, sFindEnd As String
Dim lStart As Long, lEnd As Long
sSource = Inet1.openUrl ("HTTP://www.yourwebsitehere.com")
'Initialize variables.
lStart = 1
lEnd = 1
sFindStart = "AS DA:</font></td><td><font face=arial size=" & Chr$(34) & "-1" & Chr$(34) & "><b>"
sFindEnd = "</b></font>"
'Get the document text.
'Find the start position.
lStart = InStr(lStart, sSource, sFindStart, vbTextCompare)
'Find the end postion only if the start text is found.
If lStart Then
'Add the length of the search text.
lStart = lStart + Len(sFindStart)
lEnd = InStr(lStart, sSource, sFindEnd, vbTextCompare)
If lEnd > lStart Then
Name = Mid$(sSource, lStart, lEnd - lStart)
Else
Debug.Print "name End text not found."
End If
Else
Debug.Print "name Text not found."
End If
End Sub
Add that code to your project, change the url in the Inet1.openurl line to your site, obviously you need to add an Inet control to your project. What it does is searches for the html directly in front of and following the text you wish to find and returns what is between.
The error type mismatch was likely coming from the vbnewline in the code by shirazamod, I am betting it didn't find the start text. The mid function will error if it returns 0 for the start, that is why you need to initialize the variables and allow for the possibility that it won't find the start or finish points.
Last edited by calder; Jul 1st, 2006 at 01:53 PM.
-
Jul 1st, 2006, 01:54 PM
#35
PowerPoster
Re: Grab Html Source
 Originally Posted by k0zz
I'm guessing I do something like this..
If temp(b) = "As Da:" Then temp (b + 1) And List1.AddItem(List1.ListIndex)
I don't know  ..
the results line is the part that gets the name.
Text1 = Text1 & "RESULTS: " & Replace(sTemp, sLine, "") & vbCrLf & vbCrLf
Last edited by rory; Jul 1st, 2006 at 01:58 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|