-
May 25th, 2018, 09:30 AM
#1
Thread Starter
New Member
Get text from website into textbox
The code from the text i want
HTML Code:
<pre id="thepaste" class="prettyprint">I WANT THIS TEXT INTO TEXTBOX</pre>
Thanks
-
May 25th, 2018, 10:16 AM
#2
Re: Get text from website into textbox
If the site has an API, use that instead. Scraping text from a website is pretty nearly guaranteed to fail eventually, because active sites tend to change their HTML around a whole lot.
If the ID is truly unique for the page, that would be ideal. It really should be, but it doesn't necessarily have to be. If it IS unique, then you can look for the element with that ID. You might give that a try first by looking to see how many matches you get on "thepaste", or 'id="thepaste"'. If you have only one match, that's great.
My usual boring signature: Nothing
-
May 25th, 2018, 11:45 AM
#3
Thread Starter
New Member
Re: Get text from website into textbox
This is my code
Code:
Dim victim As HtmlElement = WebBrowser1.Document.GetElementById("thepaste")
If victim IsNot Nothing Then
Textbox1.Text = victim.InnerText
End If
Last edited by babypandah; May 25th, 2018 at 11:46 AM.
Reason: hey
-
May 25th, 2018, 01:22 PM
#4
Thread Starter
New Member
Re: Get text from website into textbox
Originally Posted by Shaggy Hiker
If the site has an API, use that instead. Scraping text from a website is pretty nearly guaranteed to fail eventually, because active sites tend to change their HTML around a whole lot.
If the ID is truly unique for the page, that would be ideal. It really should be, but it doesn't necessarily have to be. If it IS unique, then you can look for the element with that ID. You might give that a try first by looking to see how many matches you get on "thepaste", or 'id="thepaste"'. If you have only one match, that's great.
It is unique
-
May 25th, 2018, 02:54 PM
#5
Re: Get text from website into textbox
Does the code work? If not, then where is it located? After all, it is entirely possible that the element hasn't loaded by the time the code is called.
My usual boring signature: Nothing
-
May 25th, 2018, 03:10 PM
#6
Re: Get text from website into textbox
Originally Posted by babypandah
This is my code
Code:
Dim victim As HtmlElement = WebBrowser1.Document.GetElementById("thepaste")
If victim IsNot Nothing Then
Textbox1.Text = victim.InnerText
End If
Now there is a non suspicious variable name :/
-
May 25th, 2018, 03:19 PM
#7
Thread Starter
New Member
Re: Get text from website into textbox
The code doesn't work, if i did i didnt had a problem, but i putted in on the Webbrowser Document Load Complete event so it should be loaded
-
May 25th, 2018, 03:50 PM
#8
Re: Get text from website into textbox
Yeah, that's a strange variable name. What does it mean?
You would expect that LoadComplete (or is it DocumentComplete) would mean that the document has finished loading. A long time back, you would have been right. Back then, web pages were simple text with some pictures embedded. You asked for a document, you got a document. When you had finished getting the document, it was complete. Those days are long gone. Modern web pages could be as simple as that, but most are not. You will likely get several such events as different parts of a page loads.
My usual boring signature: Nothing
-
May 25th, 2018, 04:14 PM
#9
Re: Get text from website into textbox
This is part of why Shaggy Hiker said to use an API if it was available.
In modern web apps, there's often a lot of magic that the JS wants to do to the page. But it needs the browser to be done with the page before it can do that. So many web apps load a relatively blank page, wait for the "document loaded" event, then use JS to load the *actual* content. That could be your page: it could be true that even after DocumentLoaded not all the content is there.
There's not a "document loaded and JS has finished executing" event. There's no need for it, from a browser's viewpoint. The web wasn't designed for screen scraping. If you can't use an API to get at the data, you're going to have to look at the page's JS and find out what it's doing to load the content you want, then simulate that yourself.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
Tags for this Thread
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
|