Windows应用程序中的WebBrowser [英] WebBrowser in Windows application
问题描述
大家好,
场景:
我有一个带有Web浏览器控件的Windows应用程序.
该网页中有数百个链接,每个链接都链接到不同的文档.
单击每个链接后,文档将加载到同一网页中.
现在是问题:
有没有一种方法可以使网页完全加载后,引发页面中的每个链接单击事件,并因此将相应的文档(除了链接的"href"之外,什么都没有)保存在指定的位置在计算机中.
[通过线程或一个接一个]
下面是我这边的一些进步.
Hi all,
Scenario:
I have a windows application with a Web Browser control in it.
There are hundreds of links in that web page, each linking to different documents.
On the click of every link, the document loads in the same webpage.
Now here is the question:
Is there a way so that after the web page is loaded completely, each of the link click event in the page is raised and hence the corresponding documents (which is nothing but ''href'' of the links) are saved in a specified location in the computer.
[either through threading or else one after another]
Below is a little progress from my side.
protected void doc_completed(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElementCollection mylinks = mywebBrowser.Document.GetElementsByTagName("A");
推荐答案
您始终可以使用 HTML Agility Pack.
You can always use Html Agility Pack.
HtmlWeb hw = new HtmlWeb();
HtmlDocument doc = hw.Load(/* url */);
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href]"))
{
}
我使用了asyn文件下载功能来下载网页中链接的所有文件.
I used the asyn file download function to download all the files that were linked in the web page.
foreach(HtmlElement single_link in mylinks)
{
WebClient client = new WebClient();
client.DownloadFileAsync(new Uri("SomeURLToFile"),"SomePlaceOnLocalHardDrive");
}
这篇关于Windows应用程序中的WebBrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!