HTML 테이블을 변환하는 방법에는 여러 가지가 있습니다 into 다음을 사용하는 JSON, CSV 또는 Excel 스프레드 시트 GrabzIt는 PHP API입니다여기에 가장 유용한 기술이 자세히 설명되어 있습니다. 그러나 시작하기 전에 전화를 한 후 URLToTable, HTMLToTable or FileToTable 방법 Save or SaveTo 테이블을 캡처하려면 메소드를 호출해야합니다. 이 서비스가 귀하에게 적합한 지 신속하게 확인하려면 HTML 테이블 캡처 라이브 데모 URL에서.
아래의 코드 예제는 지정된 웹 페이지에서 발견 된 첫 번째 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
기본적으로 이것이 식별하는 첫 번째 테이블을 변환합니다 intoa 테이블. 그러나 웹 페이지의 두 번째 테이블은 2를 setTableNumberToInclude
방법.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setTableNumberToInclude(2); $grabzIt->URLToTable("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.csv");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setTableNumberToInclude(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 = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setTableNumberToInclude(2); $grabzIt->FileToTable("tables.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.csv");
당신은 또한 사용할 수 있습니다 setTargetElement
지정된 요소 ID 내의 테이블 만 변환되도록하는 메소드입니다.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setTargetElement("stocks_table"); $grabzIt->URLToTable("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.csv");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setTargetElement("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 = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setTargetElement("stocks_table"); $grabzIt->FileToTable("tables.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.csv");
또는 웹 페이지에 true를 전달하여 웹 페이지의 모든 테이블을 캡처 할 수 있습니다. setIncludeAllTables
그러나이 방법은 XLSX 및 JSON 형식에서만 작동합니다. 이 옵션은 각 테이블을 생성 된 스프레드 시트 통합 문서 내의 새 시트에 넣습니다.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setFormat('xlsx'); $options->setIncludeAllTables(true); $grabzIt->URLToTable("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.xlsx");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setFormat('xlsx'); $options->setIncludeAllTables(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");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setFormat('xlsx'); $options->setIncludeAllTables(true); $grabzIt->FileToTable("tables.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.xlsx");
프로그래밍 방식으로 HTML 테이블을 읽을 필요가있는 경우가 있습니다. GrabzIt을 사용하면 온라인 HTML 테이블을 변환하여 PHP를 사용하여이 작업을 수행 할 수 있습니다 into JSON. 이 작업을 수행하려면 json
형식 매개 변수로 예를 들어 아래 예에서 HTML 테이블을 변환하고 있습니다. 동 기적으로 그런 다음 내장을 사용하여 json_decode
JSON을 파싱하는 PHP 메소드 string into 우리가 쉽게 작업 할 수있는 대상.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setFormat("json"); $options->setTableNumberToInclude(1); $grabzIt->URLToTable("https://www.tesla.com", $options); $json = $grabzIt->SaveTo(); if ($json != null) { $tableObj = json_decode($json); }
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setFormat("json"); $options->setTableNumberToInclude(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(); if ($json != null) { $tableObj = json_decode($json); }
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setFormat("json"); $options->setTableNumberToInclude(1); $grabzIt->FileToTable("tables.html", $options); $json = $grabzIt->SaveTo(); if ($json != null) { $tableObj = json_decode($json); }
사용자 지정 식별자를 테이블 아래 표시된대로 메소드를 사용하면이 값이 GrabzIt PHP 핸들러로 리턴됩니다. 예를 들어이 사용자 지정 식별자는 데이터베이스 식별자 일 수 있으며 추출 된 테이블을 특정 데이터베이스 레코드와 연결할 수 있습니다.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setCustomId(123456); $grabzIt->URLToTable("https://www.tesla.com", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setCustomId(123456); $grabzIt->HTMLToTable("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItTableOptions(); $options->setCustomId(123456); $grabzIt->FileToTable("example.html", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");