如何使用Web浏览器控件C#以编程方式单击链接从网站下载pdf? [英] How to download a pdf from a website by clicking links programmatically using web Browser control C# ?
问题描述
WebClient客户端=新WebClient();
HtmlElementCollection links = webBrowser1.Document.GetElementsByTagName(a);
if( dt1!= null)
{
foreach(链接中的HtmlElement链接)
{
if(!string .IsNullOrEmpty(link.OuterText))
{
DataRow rw = dt1.AsEnumerable()。FirstOrDefault(tt => tt.Field< string>(发票编号 ).ToString()。Trim()== link.OuterText.ToString()。Trim());
if(rw!= null)
{< br $>
client.Credentials = new NetworkCredential(userName,password,URL);
client.DownloadFile(URL,path +。pdf) ;
}
}
}
}
WebClient client = new WebClient();
HtmlElementCollection links = webBrowser1.Document.GetElementsByTagName("a");
if (dt1 != null)
{
foreach (HtmlElement link in links)
{
if (!string.IsNullOrEmpty(link.OuterText))
{
DataRow rw = dt1.AsEnumerable().FirstOrDefault(tt =>tt.Field<string>("Invoice Number").ToString().Trim() ==link.OuterText.ToString().Trim());
if (rw != null)
{
client.Credentials = new NetworkCredential(userName, password, URL);
client.DownloadFile(URL, path + ".pdf");
}
}
}
}
推荐答案
>
1) WebBrowser Control下载文件会议
2)使用WebBrowser Control下载文件
这篇关于如何使用Web浏览器控件C#以编程方式单击链接从网站下载pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!