你如何获得类似asp.net网页的PHP的get_file_contents标记 [英] How do you get the markup of a webpage in asp.net similar to php's get_file_contents

查看:90
本文介绍了你如何获得类似asp.net网页的PHP的get_file_contents标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做类似PHP命令get_file_contents东西拿到市场上去一个网页,但它必须是在ASP.net。我不是肯定的,如果我可以只通过文件打开网页,然后只需读取流到另一个文件。

一个念头IW的想法是:<一href=\"http://stackoverflow.com/questions/7387085/how-to-read-an-entire-file-to-a-string-using-c-sharp\">How使用C#来读取整个文件到一个字符串,但我不是肯定的,如果这是我会需要去或途径,如果别人知道的东西,会做什么,我想要的。

寻找的答案,下面的伪code:

  $测试=www.google.com;
$字符串= get_file_contents($测试);
$文件指针=的fopen(sample.txt的,W +);
$ filePointer.write($字符串);
FCLOSE($文件指针);


解决方案

 字符串的html;
使用(VAR的客户=新的WebClient())
{
    的HTML = client.DownloadString(http://www.google.com);
}
Console.WriteLine(HTML);

I was trying to do something similar to the PHP command get_file_contents to get the market up a webpage, but it has to be in ASP.net. I wasnt sure if i could just open the webpage via file, and then just read the stream into another file.

One thought iw as thinking was: How to Read an Entire file to a String using C# but i wasnt sure if that was the route i would be needing to go or if someone else knew something that would do what i wanted.

Looking for the answer to the following pseudocode:

$test = "www.google.com";
$string = get_file_contents($test);
$filePointer = fopen("sample.txt", "w+");
$filePointer.write($string);
fclose($filePointer);

解决方案

string html;
using (var client = new WebClient())
{
    html = client.DownloadString("http://www.google.com");
}
Console.WriteLine(html);

这篇关于你如何获得类似asp.net网页的PHP的get_file_contents标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆