HTML तालिकाओं को परिवर्तित करने के कई तरीके हैं intओ JSON, CSV और एक्सेल स्प्रेडशीट का उपयोग कर GrabzIt की Node.js एपीआई, यहाँ सबसे उपयोगी तकनीकों में से कुछ हैं। हालांकि इससे पहले कि आप याद रखें कि कॉल करने के बाद url_to_table, html_to_table or file_to_table तरीके save or save_to तालिका पर कब्जा करने के लिए विधि को बुलाया जाना चाहिए। यदि आप जल्दी से देखना चाहते हैं कि क्या यह सेवा आपके लिए सही है, तो आप एक कोशिश कर सकते हैं HTML तालिकाओं को कैप्चर करने का लाइव डेमो एक URL से।
यह विशेष विधि कॉल निर्दिष्ट URL के वेबपेज में पहली HTML तालिका को रूपांतरित करेगी, into CSV दस्तावेज़। यह कोड स्निपेट एक निर्दिष्ट वेबपेज या एचटीएमएल इनपुट में मिली पहली HTML तालिका को रूपांतरित करेगा into CSV दस्तावेज़।
client.url_to_table("https://www.tesla.com"); //Then call the save or save_to method
client.html_to_table("<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 save_to method
client.file_to_table("tables.html"); //Then call the save or save_to method
डिफ़ॉल्ट रूप से यह पहचानने वाली पहली तालिका को रूपांतरित कर देगा intओए टेबल। हालाँकि एक वेब पेज की दूसरी तालिका को 2 पास करके परिवर्तित किया जा सकता है tableNumberToInclude
संपत्ति।
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"tableNumberToInclude":2}; client.url_to_table("https://www.tesla.com", options); //Then call the save or save_to method client.save_to("result.csv", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"tableNumberToInclude":2}; client.html_to_table("<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 save_to method client.save_to("result.csv", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"tableNumberToInclude":2}; client.file_to_table("tables.html", options); //Then call the save or save_to method client.save_to("result.csv", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
आप भी निर्दिष्ट कर सकते हैं targetElement
वह संपत्ति जो केवल निर्दिष्ट तत्व आईडी के भीतर तालिकाओं को सुनिश्चित करेगी।
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"targetElement":"stocks_table"}; client.url_to_table("https://www.tesla.com", options); //Then call the save or save_to method client.save_to("result.csv", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"targetElement":"stocks_table"}; client.html_to_table("<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 save_to method client.save_to("result.csv", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"targetElement":"stocks_table"}; client.file_to_table("tables.html", options); //Then call the save or save_to method client.save_to("result.csv", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
वैकल्पिक रूप से आप वेब पेज पर मौजूद सभी तालिकाओं को सही से पास करके कैप्चर कर सकते हैं includeAllTables
संपत्ति, हालांकि यह केवल JSON और XLSX प्रारूपों के साथ काम करेगी। यह विकल्प जनरेट किए गए स्प्रेडशीट वर्कबुक में प्रत्येक तालिका को एक नई शीट में रखेगा।
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"format","xlsx","includeHeaderNames":true,"includeAllTables":true}; client.url_to_table("https://www.tesla.com", options); //Then call the save or save_to method client.save_to("result.xlsx", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"format","xlsx","includeHeaderNames":true,"includeAllTables":true}; client.html_to_table("<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 save_to method client.save_to("result.xlsx", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"format","xlsx","includeHeaderNames":true,"includeAllTables":true}; client.file_to_table("tables.html", options); //Then call the save or save_to method client.save_to("result.xlsx", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
Node.js और GrabzIt का उपयोग करके आप HTML तालिकाओं को परिवर्तित कर सकते हैं intओ JSON, बस निर्दिष्ट करें json
प्रारूप पैरामीटर में। जैसा कि एक बार नीचे दिए गए उदाहरण में दिखाया गया है save_to
विधि समाप्त हो गई है अपूर्ण फ़ंक्शन को JSON के साथ परिणाम चर में कहा जाता है, फिर इसे इनबिल्ट नोड्स .js द्वारा पार्स किया जाता है JSON.parse
HTML तालिका का प्रतिनिधित्व करने वाली एक वस्तु बनाने के लिए कार्य करता है।
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"format","json","includeHeaderNames":true,"includeAllTables":true}; client.url_to_table("https://www.tesla.com", options); client.save_to(null, function(error, result){ if (result != null) { var tableObj = JSON.parse(result); } });
आप एक कस्टम पहचानकर्ता को पास कर सकते हैं तालिका नीचे दिखाए गए तरीके, यह मान तब आपके GrabzIt Node.js हैंडलर को वापस कर दिया जाता है। उदाहरण के लिए, यह कस्टम पहचानकर्ता एक डेटाबेस पहचानकर्ता हो सकता है, जो स्क्रीनशॉट को किसी विशेष डेटाबेस रिकॉर्ड से जुड़ा होने की अनुमति देता है।
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.url_to_table("https://www.tesla.com", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.html_to_table("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.file_to_table("example.html", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });