从网站保存嵌入式pdf

时间:2014-10-07 07:13:12

标签: javascript c# html c#-4.0 webclient

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

目前我手动搜索化学品并保存pdf并在我的程序中添加pdf链接。问题是我还有很多化学品,所以自动化过程会更好。

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

包含pdf的链接在这里:

Link

我一直在阅读页面来源但找不到pdf的链接

但我对html / javascript的了解目前仅限于.....

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

提前感谢任何建议:)

3 个答案:

答案 0 :(得分:2)

在页面中查找ID为#34; msdsPageFrame"的iframe元素。该元素的src属性包含PDF的网址。下载该网址。

如果您对如何下载网址或如何在搜索ID时解析网页有疑问,请提出其他问题。

答案 1 :(得分:0)

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

www.sigmaaldrich.com/MSDS/MSDS/DisplayMSDSPage.do?country=NL&language=EN-generic&安培; productNumber = 271004&安培;品牌= SIAL&安培; PageToGoToURL =空

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

        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文件的问题。

答案 2 :(得分:0)

对于使用Mozilla的用户,将鼠标指针放在PDF区域内的任意位置,然后按 control + s 。这样做将下载PDF。

相关问题