我简单试了一下,web request 得到的还是原来的 HTML。我的代码(网上抄的)HttpWebRequest request = (HttpWebRequest)WebRequest.Create ("http://www.microsoft.com ");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String ver = response.ProtocolVersion.ToString();
StreamReader reader = new StreamReader(response.GetResponseStream() ); string str = reader.ReadLine();
while(str != null)
{
Console.WriteLine(str);
str = reader.ReadLine();
}光从名字看这种解释是合理的。
我觉得还不如 web browser control,因为 web browser 显然已经解释和运行了
脚本,只是我们不知道如果取得结果。
既然web browser 可以打印,那么能不能有什么方法 实现“打印到文件”,不就行了。
只是一点想法。
各位高手指正,赐教。感谢在先。急啊。
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String ver = response.ProtocolVersion.ToString();
StreamReader reader = new StreamReader(response.GetResponseStream() ); string str = reader.ReadLine();
while(str != null)
{
Console.WriteLine(str);
str = reader.ReadLine();
}光从名字看这种解释是合理的。
我觉得还不如 web browser control,因为 web browser 显然已经解释和运行了
脚本,只是我们不知道如果取得结果。
既然web browser 可以打印,那么能不能有什么方法 实现“打印到文件”,不就行了。
只是一点想法。
各位高手指正,赐教。感谢在先。急啊。
IHTMLDocument3 接口 可以遍历 frame。
这个方案或许可行。
不知道有没有愿意写一个完整一点的贴出来分享。
= (IHTMLDocument2) axWebBrowser1.Document;
IHTMLFramesCollection2 frameCollection
= (IHTMLFramesCollection2) HTMLDocumentMain.frames;string loc = "hello.htm";
if(frameCollection.length == 0) // not a frameset
{
// get document
IHTMLDocument3 HTMLDocument
= (IHTMLDocument3) axWebBrowser1.Document;
// show inner(dyn) doc in textbox
this.richTextBox1.Text =
HTMLDocument.documentElement.innerHTML;
}
else
{
// in a frameset, enumerate them
for (int i = 0; i < frameCollection.length; i++)
{
object j = (object) i;
// get doc of each frame
IHTMLWindow2 frame = (IHTMLWindow2)frameCollection.item(ref j);
IHTMLDocument2 doc = (IHTMLDocument2) frame.document; // search the specified document, say "sysinfo.htm"
string s = doc.location.href;
listBox1.Items.Add(s);
if(s.IndexOf(loc) != -1)
{
// document found, get it
IHTMLDocument3 HTMLDocumentDyn = (IHTMLDocument3) (doc);
this.richTextBox1.Text
= HTMLDocumentDyn.documentElement.innerHTML; // save it to file
const string FILE_NAME = "d:\\temp\\hello.txt";
StreamWriter sr = File.CreateText(FILE_NAME);
sr.WriteLine (HTMLDocumentDyn.documentElement.innerHTML);
sr.Close();
}
}
}
1, 在有iFrame时,frameCollection.length 也大于 0,
如何将 iFrame 过滤掉?
2,我是第一次写 C#,我知道C#不是强类型的。
所以各位能否帮忙将上面代码写得更健壮?
3,我想想实现自动登陆. 在 CSDN 上有类似的 VB 代码。但改成 C# 好像不行。请指教
IHTMLDocument2 HTMLDocumentMain
= (IHTMLDocument2) axWebBrowser1.Document;
object zero = (object) 0;
inputName = "done";
IHTMLButtonElement iSumit =
(IHTMLButtonElement)(HTMLDocumentMain.all.item(inputName, zero));
iSumit.form.sumit();