从网站保存嵌入的pdf

Save embedded pdf from website

本文关键字:pdf 网站 保存      更新时间:2023-09-26

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

目前,我手动搜索化学品,保存pdf,并在程序中添加pdf链接。问题是我还有很多化学制品要做,所以最好把这个过程自动化。

例如:化学品的零件号如下:271004

包含pdf的链接在这里:

链接

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

但我对html/javascript的了解目前还很有限。。。。。

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

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

对于那些试图在Firefox和Chrome上下载PDF文件的人,请将鼠标指针放在PDF区域内的任何位置,然后按control+s(在windows/linux上)或11+s(在mac上)。这样做将下载该文件。

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

如果您对如何下载URL或如何解析页面以搜索id有疑问,请再问一个问题。

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

www.sigmaaldrich.com/MSDS/MSDS/DisplayMSDSPage.do?country=NL&language=EN通用‌​&productNumber=271004&brand=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文件没有下载的问题。