網站通常以HTML格式提供大部分內容,但一些網站也可以提供其他格式的內容,如PDF或MS Word文檔。 Visual Web Ripper只能處理HTML,并將下載其他類型的內容作為完整的文檔。
有時,您可能希望從PDF或Word文檔中提取文本和圖像,但由于Visual Web Ripper 只理解HTML,它必須首先將這些文檔轉換為HTML。您需要為您希望看到的每一種類型的文檔提供一個外部文檔轉換器。Visual Web Ripper 公共網站提供了一個你可以使用的開源程序的列表。為了方便,我們提供了第三方工具的下載鏈接。這些工具不是我們開發的,我們不支持這些工具。您必須確保您遵守與每個工具相關的許可證。
局限性 Limitations
大多數文件格式,包括PDF和Word文件,都不打算轉換成HTML,因此轉換后的HTML頁面要比標準的HTML頁面要困難得多。在許多情況下,您必須選擇整個HTML頁面,并使用正則表達式來提取目標內容。
安裝文檔轉換器 Installing a Document Converter
Visual Web Ripper使用自定義腳本調用外部文檔轉換器,您可以配置該腳本以調用任何類型的程序。默認的腳本可以處理目前可以在Visual Web Ripper網站上下載的兩個文檔轉換器。
安裝PDF轉HTML轉換器
- Download the pdftohtml.zip file from the Visual Web Ripper website (http://www.visualwebripper.com/Resources/Tools.aspx)
- Extract the content of the zip file into the default Visual Web Ripper
Converters folder My Documents\Visual Web Ripper\Converters - The direct path to the document converter should now be
My Documents\Visual Web Ripper\Converters\pdftohtml\pdftohtml.exe
安裝DocxToHTML轉換器
- Download the docxtohtml.zip file from the Visual Web Ripper website (http://www.visualwebripper.com/Resources/Tools.aspx)
- Extract the content of the zip file into the default Visual Web Ripper
Converters folder My Documents\Visual Web Ripper\Converters - The direct path to the document converter should now be
My Documents\Visual Web Ripper\Converters\docxtohtml\docxtohtml.exe
使用文檔轉換器 Using a Document Converter
調用文檔轉換器的自定義腳本必須添加到鏈接模板中,鏈接模板必須選擇要轉換為HTML的文檔的鏈接。您還必須將模板選項“下載和轉換文檔”設置為true。
Document Conversion
默認的腳本可以處理PDF和docx文檔,看起來如下:
using System;
using System.Data;
using mshtml;
using VisualWebRipper;
public class Script
{
//See help for a definition of WrDocumentConversionArguments.
public static bool ConvertDocument(WrDocumentConversionArguments args)
{
try
{
if(args.DocumentType == "pdf")
{
ScriptUtils.ExecuteCommandLine(@"Converters\pdftohtml\pdftohtml.exe",
args.DocumentFilePath, args.HtmlFilePath, "-noframes");
}
else if(args.DocumentType == "docx")
{
ScriptUtils.ExecuteCommandLine(@"Converters\docxtohtml\docxtohtml.exe",
args.DocumentFilePath, args.HtmlFilePath, "");
}
return true;
}
catch(Exception exp)
{
args.WriteDebug("Custom script error: " + exp.Message);
return false;
}
}
}
錯誤處理 Error Handling
個項目在運行時可能會遇到三種不同類型的錯誤。
- Critical errors. 如果嵌入式Internet Explorer web瀏覽器崩潰,就會出現一個嚴重的錯誤。這樣的崩潰很少見,而且通常是由目標網站上的錯誤的JavaScript引起的。一個項目不能在一個關鍵錯誤之后繼續,并且通常會停止 Visual Web Ripper 的應用程序。您不能自動處理這樣的錯誤,但是您可以在崩潰的時候手動地繼續一個項目,或者您可以手動地將數據導出到項目崩潰的點。
- Page load errors. 如果加載一個網頁或者目標web服務器返回一個錯誤代碼,頁面加載錯誤就會發生。這是一個很常見的錯誤,這個錯誤通常不會阻止項目繼續進行。如果在分頁過程中出現了頁面加載錯誤,則該項目可能無法繼續,因為它無法訪問下一個頁面鏈接。如果在頁面加載錯誤的情況下,項目選項重試錯誤可以被設置為重試一個項目。該項目只會重試未加載的頁面。
- **Missing required elements. ** 內容元素可以被配置為需要的元素,如果頁面中缺少這樣的內容,則會被認為是頁面加載錯誤。適用于頁面加載錯誤的相同規則適用于缺少所需內容的頁面,因此您可以配置一個項目來重試缺少所需內容的頁面。