Capture web pages with ASP. NET

Source: Internet
Author: User

Demo:
Http://www.aspxboy.com/demo/286.aspx
CodeHightlight in source code Viewer)
Http://www.aspxboy.com/code/default.aspx/S7s2zPJbeI9PJA/ OK
Hpavwvauehf02egeogeb3yd5z7fll3zngdv7xiqertuoym9kbq62
Lshbjbwvwpbbya4eyvmhvmhyedph8chu5ornn8 =. aspx

<% @ Page Language = "C #" trace = "true" %>
<% @ Import namespace = "system. Net" %>
<% @ Import namespace = "system. Io" %>

<HTML>
<Head>
 

<SCRIPT runat = "server">
Void page_load (Object sender, eventargs e ){

Webrequest Req = webrequest. Create ("http://www.im286.com/index.php ");
String urliii = "src ="; // use absolute link for the image
Urliii + = "http://www.im286.com /";
Try {
Webresponse result = Req. getresponse ();
Stream receivestream = result. getresponsestream ();

Byte [] READ = new byte [512];
Int bytes = receivestream. Read (read, 0,512 );

Lblhtml. Text = "";
While (Bytes> 0)
{

// Note:
// Assume that the response uses gb2312 as the encoding method.
// If the content is sent in the form of an ANSI code page (for example, 932), use a statement similar to the following:
// Encoding encode = system. Text. encoding. getencoding ("shift-JIS ");
Encoding encode = system. Text. encoding. getencoding ("gb2312 ");
Lblhtml. Text = lblhtml. Text + encode. getstring (read, 0, bytes );

Bytes = receivestream. Read (read, 0,512 );

}
} Catch (exception ){
Lblhtml. Text = "page retrieval error ";
}
Lblhtml. Text = lblhtml. Text. Replace ("src =", "" + urliii + "");
Lblhtml. Text = lblhtml. Text. Replace ("\"","");
}
</SCRIPT>
</Head>

<Body>

<Form method = "Post" Action = "webrequest. aspx" runat = "server">

<Asp: Label runat = server id = "lblhtml" rows = "30" Cols = "80" enableviewstate = "false" Wrap = "true"> </ASP: Label>
</Form>

</Body>
</Html>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.