Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi everyone,
I'm currently working on a 'windows forms' project that requires me to get some text from a website and display it within the program.
 
I have my public sub below, which basically reads the source code of the site in question, converts it to a string from a byte, and displays it in a multi-line textbox on the form.
  Public Sub LoadSiteContent(ByVal url As String)
    Dim client As New WebClient
    Dim html As Byte() = client.DownloadData(url)
    Dim webString As String = System.Text.Encoding.UTF8.GetString(html)
    TextBox1.Text = webString
  End Sub
This sub gets all the source code, whereas I only want a specific paragraph on the site, so is there a way to scale down the string I converted to just that paragraph within the page source? Maybe through using regular expressions or substrings?
 
I also have this import at the top of my class:
Imports System.Net
Any response is greatly appreciated, thanks.
Posted 5-Dec-12 4:14am
Comments
David Goebet at 5-Dec-12 9:20am
   
so you want to try to read some special text in the "html-code" right ?
so you could search your string for a specific phrase
 
something like "<span> News News News </span>"
there you can search "<span>" ... read till "</span>"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is probably a bit more that you think you wanted, but...
The process is called "Web scraping", and there is a nice article about it here: Web Scraping in ASP.NET with Regular Expression Matching and XML Transformation[^] - it's in C#, but the code is easily translatable, and the description is very clear.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If there is a fixed text before and after that paragraph on the webpage (ex- some tag with id='xyz') you can find it in the string returned and then get the required paragraph from that. I have done this in one of my application hope it will be helpful for u also. please mark as answer if helped.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Richard MacCutchan 269
1 Aajmot Sk 252
2 Marcin Kozub 235
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100