Use WebClient to create a simple collector

Source: Internet
Author: User

Enter a URL to capture the webpage content, process it, and save it to the database. This should be the principle of the collector.
If you want to use C #, you need to use the WebClient class.

Meteorology

Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;

UsingSystem. net;

NamespaceFirstwebclient
{
Public Partial ClassForm1: Form
{
PublicForm1 ()
{
Initializecomponent ();
}

Private   Void Button#click ( Object Sender, eventargs E)
{
WebClient _ Client =   New WebClient ();
_ Client. baseaddress =   " Http://www.cnblogs.com " ;
_ Client. headers. Add ( " Accept " , " Image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, application/X-Shockwave-flash, application/vnd. MS-Excel, application/vnd. MS-PowerPoint, application/MSWord ,*/* " );
_ Client. headers. Add ( " Accept-Language " , " Zh-CN " );
_ Client. headers. Add ( " UA-CPU " , " X86 " );
// _ Client. headers. Add ("Accept-encoding", "gzip, deflate ");
_ Client. headers. Add ( " User-Agent " , " Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727) " );
System. Io. Stream objstream = _ Client. openread ( " / " );
System. Io. streamreader _ read =   New System. Io. streamreader (objstream, system. Text. encoding. utf8 );
Textbox1.text = _ Read. readtoend ();
}
}
}

 

Reference: http://www.cnblogs.com/titi/archive/2005/11/20/280914.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.