0

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" />
3
Contributors
11
Replies
24
Views
2 Years
Discussion Span
Last Post by tobyITguy
0

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#?

0
                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.

0

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?

0

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...

0

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 ();

0

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

Edited by pritaeas

0

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...

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.