वेब पर कब्जा और परिवर्तित करने के लिए उपकरण

पर्ल के साथ वेबसाइटों से HTML तालिकाओं को कैप्चर करें

पर्ल एपीआई

HTML तालिकाओं को परिवर्तित करने के निम्नलिखित उदाहरणों का उपयोग करें intओ JSON, CSV और एक्सेल स्प्रेडशीट का उपयोग कर GrabzIt के पर्ल एपीआई। हालांकि इससे पहले कि आप याद रखें कि कॉल करने के बाद URLToTable, HTMLToTable or FileToTable तरीके Save or SaveTo विधि तालिका कैप्चर को पुनः प्राप्त करना चाहिए। यदि आप जल्दी से देखना चाहते हैं कि क्या यह सेवा आपके लिए सही है, तो आप एक कोशिश कर सकते हैं HTML तालिकाओं को कैप्चर करने का लाइव डेमो एक URL से।

मूल विकल्प

नीचे पाया गया कोड उदाहरण एक निर्दिष्ट वेबपेज में खोज की गई पहली HTML तालिका को स्वचालित रूप से परिवर्तित करता है into CSV दस्तावेज़।

$grabzIt->URLToTable("https://www.tesla.com");
# Then call the Save or SaveTo method
$grabzIt->HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr>
    <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr>
    </table></body></html>");
# Then call the Save or SaveTo method
$grabzIt->FileToTable("tables.html");
# Then call the Save or SaveTo method

डिफ़ॉल्ट रूप से यह पहचानने वाली पहली तालिका को रूपांतरित कर देगा intओए टेबल। हालाँकि एक वेब पेज की दूसरी तालिका को 2 पास करके परिवर्तित किया जा सकता है tableNumberToInclude विधि.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->tableNumberToInclude(2);

$grabzIt->URLToTable("https://www.tesla.com", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.csv");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->tableNumberToInclude(2);

$grabzIt->HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr>
    <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr>
    </table></body></html>", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.csv");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->tableNumberToInclude(2);

$grabzIt->FileToTable("tables.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.csv");

आप भी निर्दिष्ट कर सकते हैं targetElement वह विधि जो निर्दिष्ट तत्व आईडी के भीतर केवल तालिकाएँ सुनिश्चित करेगी, परिवर्तित हो जाएगी।

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->targetElement("stocks_table");

$grabzIt->URLToTable("https://www.tesla.com", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.csv");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->targetElement("stocks_table");

$grabzIt->HTMLToTable("<html><body><table id='stocks_table'><tr><th>Name</th><th>Age</th></tr>
    <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr>
    </table></body></html>", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.csv");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->targetElement("stocks_table");

$grabzIt->FileToTable("tables.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.csv");

वैकल्पिक रूप से आप वेब पेज पर मौजूद सभी तालिकाओं को सही से पास करके कैप्चर कर सकते हैं includeAllTables विधि, हालांकि यह केवल XLSX प्रारूप के साथ काम करेगा। यह विकल्प जेनरेट किए गए स्प्रेडशीट वर्कबुक में प्रत्येक तालिका को एक नई शीट में रखेगा।

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->format('xlsx');
$options->includeAllTables(1);

$grabzIt->URLToTable("https://www.tesla.com", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.xlsx");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->format('xlsx');
$options->includeAllTables(1);

$grabzIt->HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr>
    <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr>
    </table></body></html>", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.xlsx");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->format('xlsx');
$options->includeAllTables(1);

$grabzIt->FileToTable("tables.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.xlsx");

HTML टेबल्स को JSON में कनवर्ट करें

पर्ल और GrabzIt के साथ आप पाया HTML तालिकाओं परिवर्तित कर सकते हैं intओ जानसन। आरंभ करने के लिए निर्दिष्ट करें json प्रारूप पैरामीटर में। उदाहरण में हम एक बना रहे हैं तुल्यकालिक कॉल का उपयोग करके SaveTo विधि, जो JSON लौटा रही है string, तो इस तरह एक पुस्तकालय द्वारा पार्स किया जा सकता है JSON :: पार्स.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->format("json");
$options->tableNumberToInclude(1);

$grabzIt->URLToTable("https://www.tesla.com", $options);

$json = $grabzIt->SaveTo();
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->format("json");
$options->tableNumberToInclude(1);

$grabzIt->HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr>
    <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr>
    </table></body></html>", $options);

$json = $grabzIt->SaveTo();
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->format("json");
$options->tableNumberToInclude(1);

$grabzIt->FileToTable("tables.html", $options);

$json = $grabzIt->SaveTo();

कस्टम पहचानकर्ता

आप एक कस्टम पहचानकर्ता को पास कर सकते हैं तालिका नीचे दिखाए गए तरीके, यह मान तब आपके GrabzIt Perl हैंडलर को वापस कर दिया जाता है। उदाहरण के लिए, यह कस्टम पहचानकर्ता एक डेटाबेस पहचानकर्ता हो सकता है, जो स्क्रीनशॉट को किसी विशेष डेटाबेस रिकॉर्ड से जुड़ा होने की अनुमति देता है।

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->customId("123456");

$grabzIt->URLToTable("https://www.tesla.com", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->customId("123456");

$grabzIt->HTMLToTable("<html><body><h1>Hello World!</h1></body></html>", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItTableOptions->new();
$options->customId("123456");

$grabzIt->FileToTable("example.html", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");