HTMLテーブルを変換する方法は複数あります into JSON、CSV、およびExcelスプレッドシートを使用 GrabzItのASP.NET APIここで詳しく説明するのは、最も便利なテクニックの一部です。 ただし、開始する前に、 URLToTable, HTMLToTable or FileToTable メソッド Save or SaveTo メソッドを呼び出してテーブルをキャプチャする必要があります。 このサービスが適切かどうかをすばやく確認したい場合は、 HTMLテーブルのキャプチャのライブデモ URLから。
次のコード例は、指定されたWebページの最初のHTMLテーブルを変換します intoa 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テーブル。 ただし、Webページの2番目のテーブルは、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
指定された要素ID内のテーブルのみが変換されることを保証するプロパティ。
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");
または、trueを渡すことにより、Webページ上のすべてのテーブルをキャプチャできます。 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");
GrabzItは、以下に示すようにJSON形式を指定するだけで、HTMLテーブルをJSONに変換することもできます。 ここでは、データを同期的に読み取ります into GrabzItFile
を使用してオブジェクト SaveTo
メソッド、ただし、一般的にこれを行うことをお勧めします 非同期的に を代わりにお使いください。
結果が得られたら、 string を呼び出すことによるJSONファイルの表現 ToString
メソッド、これはその後、逆シリアル化することができます 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");