Scraping webpages and displaying data from it…

When you are working on a project to get data from a webpage but you don’t have access to the back-end database or a API to get any values out.

The workaround I use until something changes is Web scraping.

I have a project with this problem – it’s another VB.NET one.

My Scraping code goes along like this –

'Get the URL / Navigate a browser window too it (this is hidden in my project
WebBrowser.Navigate("http://website.com/pageiwanttoscrape.aspx")

'Convert the HTML of the page to a string using the body.outerhtml function
webPage1 = WebBrowser.Document.Body.OuterHtml

'Use the InString function to search for a term in the webPage1 string
If InStr(webPage1, "term to search") <> 0 Then
'get the position of the term to search
            StringSearch = InStr(webPage1, "term to search")
'pick some deatails out of the page using the position + x and capture the next n letters
            ScrapedText = Mid(webPage1, StringSearch + x, n)
'tidy up anything we don't like out of the returned string 
            ScrapedText = ScrapedText.Replace(".", "")
'now we have the scraped text we can use it in our app
       

        End If

Ta-da – workaround using scraping.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.