从网页下载源代码时遇到问题
我正在尝试使用 c# 下载此网页的源代码,用于学校项目。
这是我想要获取的页面:
http://www.epicurious.com/tools/fooddictionary/entry?id=1650
我已经尝试过诸如
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://www.epicurious.com/tools/fooddictionary/entry?id=1650");
和 by using 之
WebClient client = new WebClient();
string value = client.DownloadString("http://www.epicurious.com/tools/fooddictionary/entry?id=1650");
类的代码,但两种方法都无法获取页面源代码。任何帮助将不胜感激。
Im trying to download the source code for this webpage for a school project using c#.
this is the page im trying to get:
http://www.epicurious.com/tools/fooddictionary/entry?id=1650
I have tried code such as
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://www.epicurious.com/tools/fooddictionary/entry?id=1650");
and by using
WebClient client = new WebClient();
string value = client.DownloadString("http://www.epicurious.com/tools/fooddictionary/entry?id=1650");
and neither methods are getting me the page source. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 HttpWebRequest.Create
使用 DownloadString
以上方法对我来说效果很好。检查是否有异常..
using HttpWebRequest.Create
Using DownloadString
Above methods are working fine for me. Check the exception if any..
这个怎么样...
“using”语句将为您关闭您的流。注意:在流上调用 close 也会在它正在使用的任何流上调用类,这就是为什么您只需要单个 using 语句
How about this...
The "using" statement will close your streams for you. NOTE: Calling close on a stream will also call class on any streams it is using, this is why you only need the single using statement