首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从网站保存嵌入的pdf

从网站保存嵌入的pdf
EN

Stack Overflow用户
提问于 2014-10-07 15:13:12
回答 2查看 42.2K关注 0票数 3

我正在写一个小的C#应用程序来管理我们的供应商的安全数据表(化学品)。

目前,我手动搜索化学品,保存pdf,并在我的程序中添加一个指向pdf的链接。问题是我仍然有很多化学物质要去,所以最好是自动化这个过程。

例如:一种化学品具有以下部件号: 271004

包含pdf的链接如下:

Link

我一直在阅读页面源代码,但找不到pdf的链接。

但目前我对html/javascript的了解有限……

有没有办法从网站上提取pdf文件?

提前感谢您的任何建议:)

EN

回答 2

Stack Overflow用户

发布于 2014-10-07 15:31:53

在页面中查找id为"msdsPageFrame“的iframe元素。该元素的src属性包含指向您的PDF的url。下载该url。

如果您有关于如何下载URL或如何在搜索id时解析页面的问题,请询问另一个问题。

票数 3
EN

Stack Overflow用户

发布于 2014-10-07 17:20:01

现在,我可以使用产品代码直接访问pdf文件:

www.sigmaaldrich.com/MSDS/MSDS/DisplayMSDSPage.do?country=NL&language=EN-generic‌​&productNumber=271004&brand=SIAL&PageToGoToURL=null

使用以下代码,我尝试下载pdf:

代码语言:javascript
复制
        private void Download()
    {
        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);                   // Uses the Event Handler to check whether the download is complete
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);  // Uses the Event Handler to check for progress made
        webClient.DownloadFileAsync(new Uri("http://www.sigmaaldrich.com/MSDS/MSDS/DisplayMSDSPage.do?country=NL&language=EN-generic&productNumber=271004&brand=SIAL&PageToGoToURL=null"), @"C:\Users\test\Downloads\newfile.pdf");           // Defines the URL and destination directory for the downloaded file
    }

    private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        Debug.WriteLine("DownloadProgressChangedEventHandler");
    }

    private void Completed(object sender, AsyncCompletedEventArgs e)
    {
        Debug.WriteLine("AsyncCompletedEventHandler");
    }

然而,这并不起作用。问题是首先生成pdf (需要几秒钟)。但是,AsyncCompletedEventHandler会立即触发。我认为这就是为什么pdf文件没有下载的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26230485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档