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

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

ASP.NET API

HTML तालिकाओं को परिवर्तित करने के कई तरीके हैं intओ JSON, CSV और एक्सेल स्प्रेडशीट का उपयोग कर GrabzIt के ASP.NET एपीआई, यहाँ सबसे उपयोगी तकनीकों में से कुछ हैं। हालांकि इससे पहले कि आप याद रखें कि कॉल करने के बाद 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 संपत्ति।

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

TableOptions options = new TableOptions();
options.TableNumberToInclude = 2;

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

TableOptions options = new TableOptions();
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");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

TableOptions options = new TableOptions();
options.TableNumberToInclude = 2;

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

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

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

TableOptions options = new TableOptions();
options.TargetElement = "stocks_table";

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

TableOptions options = new TableOptions();
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");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

TableOptions options = new TableOptions();
options.TargetElement = "stocks_table";

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

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

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

TableOptions options = new TableOptions();
options.Format = TableFormat.xlsx;
options.IncludeAllTables = true;

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

TableOptions options = new TableOptions();
options.Format = TableFormat.xlsx;
options.IncludeAllTables = true;

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");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

TableOptions options = new TableOptions();
options.Format = TableFormat.xlsx;
options.IncludeAllTables = true;

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

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

GrabzIt HTML टेबल को JSON में भी परिवर्तित कर सकता है, बस JSON प्रारूप निर्दिष्ट करें जैसा कि नीचे दिखाया गया है। यहां हम डेटा को सिंक्रोनाइज़ कर रहे हैं intओ GrabzItFile का उपयोग करके वस्तु SaveTo विधि, हालांकि आमतौर पर यह सिफारिश की जाती है कि आप ऐसा करते हैं अतुल्यकालिक रूप से बजाय.

एक बार जब हम परिणाम है हम प्राप्त करते हैं string कॉल करके JSON फ़ाइल का प्रतिनिधित्व ToString विधि, यह तब deserialized किया जा सकता है intअपने पसंदीदा JSON लाइब्रेरी का उपयोग करके ओ डायनेमिक ऑब्जेक्ट।

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

TableOptions options = new TableOptions();
options.Format = TableFormat.json;
options.TableNumberToInclude = 1;

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

GrabzItFile file = grabzIt.SaveTo();
if (file != null)
{
    string json = file.ToString();
}
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

TableOptions options = new TableOptions();
options.Format = TableFormat.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);

GrabzItFile file = grabzIt.SaveTo();
if (file != null)
{
    string json = file.ToString();
}
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

TableOptions options = new TableOptions();
options.Format = TableFormat.json;
options.TableNumberToInclude = 1;

grabzIt.FileToTable("tables.html", options);

GrabzItFile file = grabzIt.SaveTo();
if (file != null)
{
    string json = file.ToString();
}

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

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

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

TableOptions options = new TableOptions();
options.CustomId = "123456";

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

TableOptions options = new TableOptions();
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/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

TableOptions options = new TableOptions();
options.CustomId = "123456";

grabzIt.FileToTable("example.html", options);
//Then call the Save method
grabzIt.Save("http://www.example.com/Home/Handler");