2014-10-07 75 views
1

我正在编写一个小型C#应用程序来管理我们的供应商提供的化学品安全数据表。从网站保存嵌入式pdf

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

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

包含PDF链接是在这里:

Link

我一直在阅读页面的源代码,但无法找到一个链接PDF格式

但我的HTML/JavaScript的知识是有限的,以目前.....

是有什么办法从网站上提取PDF文件?

预先感谢任何建议:)

+2

简答:是的,有一种方法。附录:[你试过什么](http://www.whathaveyoutried.com)? – SynerCoder 2014-10-07 07:28:16

回答

1

查找在ID为“msdsPageFrame” iframe元素的页面。该元素的src属性包含您的PDF的网址。下载该网址。

如果您有关于如何下载URL或如何解析页面以搜索ID的问题,请提出另一个问题。

+0

你好,谢谢你的回复。唯一的问题是链接中的数字与零件号码无关,所以很难自动化。我希望能够根据产品编号获得pdf。 – 2014-10-07 07:53:30

+1

@JR_您可以自动化,该号码位于原始网址中,因此请下载原始网址并对其进行解析。找到id“msdsPageFrame”。阅读src属性,下载该链接并完成! – SynerCoder 2014-10-07 07:58:42

+0

你是什么意思“数字是原始URL”?该pdf的网址为http://www.sigmaaldrich.com/MSDS/MSDS/PrintMSDSAction.do?name=msdspdf_1410280031038377。这个数字(1410280031038377)与零件编号或“原始网址” – 2014-10-07 08:12:47

-1

现在我能够使用的产品代码访问PDF文件直接:

www.sigmaaldrich.com/MSDS/MSDS/DisplayMSDSPage.do?country=NL &语言= EN-通用& productNumber = 271004 &品牌= SIAL & PageToGoToURL = NULL

使用下面的代码我尝试下载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文件没有下载的问题。