|
-
Dec 23rd, 2012, 05:10 AM
#1
Thread Starter
Lively Member
Webbrowser.Sourcecode reading + gathering text(+finding)(code) + dropping in txtbox
So, all of you..
Hello..
I'm working on a small project, and really FAIL so hard at this, I've googled for almost half of an hour, with no luck.
I let my webbrowser1 navigate to a page after the user clicks on the button.
So, my thing: On that page, there's something in the source what the USER needs. ([s]he can do CTRL+U CTRL+F but that's not humanfriendly at all!)
This is the part of that page I need dropped in a textbox:
(The part I need is blue because it's a link and it's underlined, that part is what I need from the source code)
<a href="/url?q=http://www.whattheUSERwrote.com/..">http://www.whatthEUSERWROTE.com/..</a>
(This is a part from the page, and I just need that underlined dropped in a textbox, or even copied to clipboard (Clipboard.SetText)
I know this sounds impossible but anyone please?;x ;((
IDEA/HELP/HINT: YOU COULD GET IT MAYBE WITH LETTING IT COPY EVERYTHING BETWEEN THE QUOTES BEHIND url?q= because there's only one url?q= in the whole source-code.
I hope you all understand me, and can help me
Thanks in advance!x
-
Dec 23rd, 2012, 05:17 AM
#2
Thread Starter
Lively Member
Re: Webbrowser.Sourcecode reading + gathering text(+finding)(code) + dropping in txtb
bump
-
Dec 23rd, 2012, 08:16 AM
#3
Hyperactive Member
Re: Webbrowser.Sourcecode reading + gathering text(+finding)(code) + dropping in txtb
this may help get the ball rolling..have you tried
Code:
Dim strAuthorCode As String = sender.Document.Body.InnerText
or if you want to save it to a text file
Dim HtmlFile = "C:\whatever.txt"
Dim HTMlAuthorCode As String = sender.DocumentText
My.Computer.FileSystem.WriteAllText(HtmlFile, HTMlAuthorCode, False)
either way once you have the source code you can use instr to locate the line or starting text you want then locate something after the text you want then hone in on the part you want..and this part is probably not the best solution but it should work. Once you have the Source that is.
Code:
Dim UrlStart As Integer = InStr(HtmlFile, "<a href="/url?q=")
Dim UrlEnd As Integer = InStr(UrlStart , HtmlFile, "</A>")
Dim UrlLink = Mid(HtmlFile, UrlStart + 21, UrlEnd - UrlStart - 26) <-----you'll have to change these numbers to hone in on the exact part you want
This is just an example you can mess with it until you find something else?
these would go in the webbrowser1_completed sub
Last edited by M@dH@tter; Dec 23rd, 2012 at 08:37 AM.
-
Dec 23rd, 2012, 12:13 PM
#4
Re: Webbrowser.Sourcecode reading + gathering text(+finding)(code) + dropping in txtb
I'm not sure somebody who bumps after just 7 minutes actually deserves help!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 24th, 2012, 06:53 AM
#5
Hyperactive Member
Re: Webbrowser.Sourcecode reading + gathering text(+finding)(code) + dropping in txtb
hehe yeah I didn't notice that until ya mentioned it lol..but what the heck i was waiting for a reply to one of my post..and was doing nothing more than pickin' lint from my naval.and scratchin' my head..so i had to have something else to do hehe
-
Dec 24th, 2012, 02:06 PM
#6
Thread Starter
Lively Member
Re: Webbrowser.Sourcecode reading + gathering text(+finding)(code) + dropping in txtb
 Originally Posted by M@dH@tter
this may help get the ball rolling..have you tried
Code:
Dim strAuthorCode As String = sender.Document.Body.InnerText
or if you want to save it to a text file
Dim HtmlFile = "C:\whatever.txt"
Dim HTMlAuthorCode As String = sender.DocumentText
My.Computer.FileSystem.WriteAllText(HtmlFile, HTMlAuthorCode, False)
either way once you have the source code you can use instr to locate the line or starting text you want then locate something after the text you want then hone in on the part you want..and this part is probably not the best solution but it should work. Once you have the Source that is.
Code:
Dim UrlStart As Integer = InStr(HtmlFile, "<a href="/url?q=")
Dim UrlEnd As Integer = InStr(UrlStart , HtmlFile, "</A>")
Dim UrlLink = Mid(HtmlFile, UrlStart + 21, UrlEnd - UrlStart - 26) <-----you'll have to change these numbers to hone in on the exact part you want
This is just an example you can mess with it until you find something else?
these would go in the webbrowser1_completed sub
Well, I did put that in WebBrowser1_DocumentCompleted (there's no completed) and got all of these errors:
Code:
Error 1 The '?' character cannot be used here. C:\Users\hicran\Documents\Visual Studio 2008\Projects\..\xX.vb 13 65
Error 2 Name 'UrlStart' is not declared. C:\Users\hicran\Documents\Visual Studio 2008\Projects\..\xX.vb 14 39
Error 3 Name 'HtmlFile' is not declared. C:\Users\hicran\Documents\Visual Studio 2008\Projects\..\xX.vb 14 49
Error 4 Name 'HtmlFile' is not declared. C:\Users\hicran\Documents\Visual Studio 2008\Projects\..\xX.vb 15 27
Error 5 Name 'UrlStart' is not declared. C:\Users\hicran\Documents\Visual Studio 2008\Projects\..\xX.vb 15 37
Error 6 Name 'UrlStart' is not declared. C:\Users\hicran\Documents\Visual Studio 2008\Projects\..\xX.vb 15 61
And I really don't know how to declare these,
also sorry for the bump, since this is a active forum I thought of that the thread would 'dissapear' between newer posts and was scared this would NEVER been answered, anyway thanks all, but any idea?..
I'm not very BEGINNER-level at VB.Net but I have no idea at all how to declare these functions.
-
Dec 24th, 2012, 05:11 PM
#7
Hyperactive Member
Re: Webbrowser.Sourcecode reading + gathering text(+finding)(code) + dropping in txtb
vb form design window at the top left there is a drop down list..click on your browser..on the right there's another drop down list..choose document completed when it post the code for that sub pop all the stuff i typed into that window that you want to try..you don't have to dim anything i already typed it exactly how it should be..the only thing you have to change is the numbers..if this doesn't help then you need to google for save html source code to text file..i know for fact there's plenty to look at..cause at one point i needed to do this exact same thing
if you typed the completed subbyhand you probably missed all the stuff that makes it work..like handle it should all look like this.
Code:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
following the above instructions this is what you should get
Last edited by M@dH@tter; Dec 24th, 2012 at 05:17 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
|