1

此源代码抓取不起作用;它给出一个空白文本文件作为输出:

private void button2_Click(object sender, EventArgs e)
{
    webBrowser1.Navigate("https://www.jigsaw.com/SearchCompany.xhtml?opCode=refresh&rpage=20&order=0&orderby=0&industry=1160000&subindustry=1160300&country=9000&country=2000&cmDead=false&count=0&screenNameType=0&screenName=&omitScreenNameType=0&omitScreenName=&rowsPerPage=200&uid=13473859&tok=1354716874406-8761960955252771794");

    string MainsourceCode = webBrowser1.DocumentText;
    StreamWriter sw = new StreamWriter("G:/jigsaw_info.txt", true);
    sw.Write(MainsourceCode + "\n");
    sw.Close();
}
4

2 回答 2

2

你开始写得太快了。你应该等待DocumentCompleted事件。

private void button2_Click(object sender, EventArgs e) 
{ 
    webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
    webBrowser1.Navigate("https://www.jigsaw.com/SearchCompany.xhtml?opCode=refresh&rpage=20&order=0&orderby=0&industry=1160000&subindustry=1160300&country=9000&country=2000&cmDead=false&count=0&screenNameType=0&screenName=&omitScreenNameType=0&omitScreenName=&rowsPerPage=200&uid=13473859&tok=1354716874406-8761960955252771794");
}

void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
      File.WriteAllText("G:/jigsaw_info.txt",webBrowser1.DocumentText);    
}   
于 2012-12-05T16:27:45.153 回答
0

您必须等到导航完成。导航是异步的。

检测 WebBrowser 完整页面加载

于 2012-12-05T16:27:59.973 回答