2010-02-28 4 views
5

HTML < 테이블에 포함 된 웹 페이지에서 일부 정보를 추출하고 싶습니다.> 어떻게 모든 테이블 정보를 좋은 것으로 추출 할 수 있습니까? 분리 된 파일? 매개 변수는 다음 위의 출력을 제공으로Common Lisp에서 HTML 테이블 스크랩하기?

 
Author|Book|Year|Comments 
Bill Bryson|Short History of Nearly Everything|2004 
Stephen Hawking|A Brief History of Time|1998|Still haven't read. 

이상적으로, 나는 URL 및 출력 파일을받는 함수를 가지고 싶습니다. 상기 출력

 
(defun extract-table (url filename) 
     (extract-from-html-table (fetch-web-page url))) 

(extract-table "http://www.mypage.com" "output.txt") 

샘플 HTML 입력 : 데이터를 페치 Drakma

 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 
<html> 
<head> 
<title>Lisp</title> 
</head> 
<body> 
<h1>Welcome to Lisp</h1> 
<table class="any" style="font-size: 14px;"> 
    <TR class="header"> 
    <td>Author</td> 
    <TD>Book</TD> 
    <td>Year</td> 
    <td>Comments</td> 
    </TR> 
    <tr class="odd"> 
    <td>Bill Bryson</td> 
    <td>Short History of Nearly Everything</td> 
    <td>2004</td> 
    </tr> 
    <tr> 
    <td>Stephen Hawking</td> 
    <td>A Brief History of Time</td> 
    <td>1998</td> 
    <td>Still haven't read.</td> 
    </tr> 
</table> 
</body> 
</html> 

답변

7

시작. 구문을 분석하려면 cxml이 도움이 될 수 있습니다. 또는 더 나은 방법은 closure-html을 사용할 수 있습니다. 이는 임의의 HTML 4를 구문 분석해야합니다. closure-html 패키지의 Common-Lisp.net 페이지는 screen scraping example입니다.

관련 문제