웹 캡처 및 변환 도구

Perl을 사용하여 웹 사이트에서 HTML 테이블 캡처

펄 API

HTML 테이블을 변환하는 방법에 대한 다음 예제를 사용하십시오. into JSON, CSV 및 엑셀 스프레드 시트 GrabzIt은 Perl 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를 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 지정된 요소 ID 내의 테이블 만 변환되도록하는 메소드입니다.

$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");

또는 웹 페이지에 true를 전달하여 웹 페이지의 모든 테이블을 캡처 할 수 있습니다. 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으로 변환

Perl과 GrabzIt을 사용하면 찾은 HTML 테이블을 변환 할 수 있습니다 into JSON. 시작하려면 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");