写一个C#爬虫代码
using System;
using System.Net; //需要引用的命名空间
using System.IO; //需要引用的命名空间
namespace WebCrawler
{
class Program
{
static void Main(string[] args)
{
string url = "http://www.baidu.com";//爬取的地址,这里是百度首页
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);//实例化web访问类
StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8);//创建流读取对象并读取网页内容
string html = reader.ReadToEnd();//读取网页内容存入字符串变量html中
Console.WriteLine("此次抓取的内容是:
" + html);//打印出html字段中的所有内容,即为我们想要的文本信息。
}
}
}
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!