I need help with .net c# screen scrape. I can't seem to find an example in c# that works. I have this one in VB that wors but feel like an idiot bc I can't convert it correctly...

<%@ Import Namespace="System.Net" %> <script language="VB" runat="server">

  Sub Page_Load(sender as Object, e as EventArgs)
    'STEP 1: Create a WebClient instance
    Dim objWebClient as New WebClient()


    'STEP 2: Call the DownloadedData method
  '  Const strURL as String = "http://www.aspmessageboard.com/"
 Const strURL as String = "http://www.expedia.com/Hotel-Search?#&destination=Helen, Georgia, United States of America&startDate=04/27/2015&endDate=04/30/2015®ionId=6057994&adults=2"
'  Const strURL as String = "http://www.grouphousingadmin.com"
    Dim aRequestedHTML() as Byte

    aRequestedHTML = objWebClient.DownloadData(strURL)

    'STEP 3: Convert the Byte array into a String
    Dim objUTF8 as New UTF8Encoding()
    Dim strRequestedHTML as String
    strRequestedHTML = objUTF8.GetString(aRequestedHTML)


    'WE'RE DONE! - display the string
    lblHTMLOutput.Text = strRequestedHTML
  End Sub
</script> <html> <body> <h1>Screen Scrape of www.aspmessageboard.com</h1> <p> <asp:label id="lblHTMLOutput" runat="server" />

Recommended Answers

All 11 Replies

all i see in the VB code is that your downloading a webpage, saving it as a string and then displaying it in a paragraph. Is that what you mean by screen scrape? Is that what you wanna do in c#?

yes, that is exactly what i want to do, but only in c#

                WebClient client = new WebClient ();
                Uri uri = new Uri ("http://yourUrl.com");       


                var pageBytes = client.DownloadData(uri);
                var pageStrings = Encoding.UTF8.GetString(res);

Then you can find a way to render the pageStrings content.

so, now i get an error that says : CS0246: The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)

I tried adding

using System.Net.Http;
and System.Net.HttpClient;

but none of those are working.. what do i need to add?

using System.Net.WebClient; this didnt help me either.. I'm still getting the "CS0246: The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)" error...

you need to use

using System.Net;

at this point i have:

using System;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Net;
using System.IO;
using System.Web;
using System.Web.Services;
using System.Web;
using System.Web.UI;
using System.Net.WebClient;

so using System.Net; is in there but still not working on this line:
WebClient client = new WebClient ();

What's the error, still the same? What kind of application or you building? Try HttpClient and see if that works.

the error is "CS0246: The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)". and I
am using all of the following:

using System;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Net;
using System.IO;
using System.Web;
using System.Web.Services;
using System.Web;
using System.Web.UI;
using System.Net.WebClient;

What is the syntax for HttpClient because when I try to add it is says it is wrong or not an object...

I just need a working exampke of a screen scrape in c# so i can pull info of one page and inlcude it in mine...

remove System.Net.WebClient
or replace WebClient client = new WebClient ();
with System.Net.WebClient client = new WebClient ();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.