Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:00:49+00:00 2026-06-06T12:00:49+00:00

I need to retrieve a value from a website (can vary and I have

  • 0

I need to retrieve a value from a website (can vary and I have no control over the site). I currently have some code that works… but takes a very long time to run. I know that there is a vastly improved way of doing this, I just don’t know what that is.

I have considered several alternatives like Regex and the HTMLAgilityPack (seems complex and possibly overkill?) but without trying each of them I am not sure what would be most efficient. And I am sure there are many more possibilities as well.

The problem may even be with how I am retrieving the page rather than how I am processing it.

    Dim GETURL As WebRequest
    GETURL = WebRequest.Create("http://www.example.com")
    Dim objStream As Stream = GETURL.GetResponse.GetResponseStream()

    Dim objReader As New StreamReader(objStream)
    Dim sLine As String = ""
    Dim a As Integer = 0
    Dim result As String = ""
    Do While Not sLine Is Nothing
        a += 1
        sLine = objReader.ReadLine
        If Not sLine Is Nothing Then
            result += sLine
        End If
    Loop

    Dim startTag as string ="<some html tag>"
    Dim endTag as string ="<closing tag>"
    Dim firstIndex As Integer = result.IndexOf(startTag) + startTag.Length
    result = result.Substring(firstIndex, result.Length - firstIndex)
    Dim RequiredVal As String = result.Substring(0, result.IndexOf(endTag))

Please note, I do realise just how hideously inefficient this code is, but rather than try loads of different permutations (and probably still have fairly inefficient code), I thought I would ask some experts for their advice first 🙂

UPDATE:

As I didn’t get any response (perhaps my question was a little too vague?) I have been trying to improve efficiency on my own. I have managed to decrease the time it takes to run by ~50% by using WebCient.DownloadString(). This is good but I suspect I can make improvements on extracting the data from the page. Please see updated code below:

    Dim client As New WebClient()
    Dim result As String = client.DownloadString("http://www.example.com")

    Dim startTag as string ="<some html tag>"
    Dim endTag as string ="<closing tag>"
    Dim firstIndex As Integer = result.IndexOf(startTag) + startTag.Length
    result = result.Substring(firstIndex, result.Length - firstIndex)
    Dim RequiredVal As String = result.Substring(0, result.IndexOf(endTag))

Any Suggestions would be greatly apprieciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:00:50+00:00Added an answer on June 6, 2026 at 12:00 pm

    If your problem is with waiting for the response from the web request, then the actual engine or technique you use to parse it probably has a lot less to do with performance, than simply waiting for each response from the web synchronously. If you have a long list of pages you’re scraping, then you can do better by running simultaneous requests asynchronously. It’s not clear that’s what is going on though.

    Try CsQuery – also on NuGet – a new C# port of jQuery which should do what you want. It has methods for grabbing data synchronously and asynchronously, so if you did want to start parallel web requests, it can do that out of the box. At the most basic level though, the code would be this to do it synchronously:

    CQ doc = CQ.CreateFromUrl("http://www.jquery.com");
    
    string allStuffInsideTag = doc["sometag"].Contents().RenderSelection();
    

    It works like jquery. The “CQ” object is the same as a jQuery object. Contents is the jQuery method to return all children of an element; RenderSelection is a CsQuery method that renders the full HTML of every element in the selection set. So this would return the full text & html of everything inside every sometag block.

    Also it indexes each document for all common selector types and is much faster than HTML Agility Pack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In several places I have to retrieve some value from a dict, but need
I have a function that takes a parameter(key) to retrieve it's value from a
I need to retrieve a value for a clickable button using jquery. I have
I need to retrieve a value from the AndroidManifest.xml file, stored as a meta
For example I need to retrieve a value from this session. How should I
i need to retrieve value from existing database through phonegap.How to do it?
I need to retrieve a value in as3 from a html page on a
That´s a general question. I need do retrieve the value of about 20 strings
I'm trying to retrieve the text value from a JTextField but first I need
I need to retrieve random rows from SQL Server database. I am looking for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.