2014-07-21 5 views
-2

나는 대학 미니 프로젝트의 초기 단계에 있으며 붙어 있습니다.Perl을 사용하여 HTML에서 데이터 추출

누구나 코드와 함께 "Perl을 사용하여 HTML 페이지에서 데이터 추출하기"의 기본 개념과 고급 개념을 알려주십시오.

yjrm이 아니라면 개념과 관련된 리소스를 살펴보고 나 혼자서 배울 수있는 경로를 보여주십시오.

+0

가능한 중복 [그렙을 펄에서 데이터를 추출] (HT를 tp : //stackoverflow.com/questions/2886200/grep-and-extract-data-in-perl) – MarmiK

+0

질문이 너무 광범위하다고 생각하지 않습니다. CPAN 모듈의 양에 직면 해 있습니다. "2014 년 7 월에 어디에서 시작할 수 있습니까?" 완벽하게 합법적 인 사람입니다. 이 답변은 모듈 문서 목록을 좁히고이 시점에서 커뮤니티가 관련, 유지 보수 및 일반적으로 수락 한 답변을 읽습니다. – mirod

답변

2

시작해야합니다.

#!/usr/bin/perl 

use strict; 
use warnings; 
use autodie; 
use LWP::Simple; #For getting a websites HTML also see LWP::UserAgent 
use HTML::Tree; #Use a parser to parse HTML, read the docs on CPAN 


#Use LWP get a page's contents 
#We'll use the url to this question http://stackoverflow.com/questions/24858906/data-extraction-from-html-using-perl 
my $url = "http://stackoverflow.com/questions/24858906/data-extraction-from-html-using-perl"; 


#All the html will be in content 
my $content = get($url); 

my $p = HTML::Tree->new(); 

#parse the string in $content. You can also parse_from_file or parse_from_url 
#Though for learning sake you should get used to LWP 
$p->parse($content); 

#Check HTML::Element documentation for the data manipulation part 
my $post = $p->find_by_attribute('class', 'post-text'); 

#Should print your question out. 
print $post->as_text(); 

지금에 대한 문서 검토 :의

LWP::Simple

LWP::UserAgent

HTML::Tree

HTML::Element

+0

나중에 Gabs. 감사합니다, 내가 그것을 밖으로 시도해보십시오 .. 내가 실제로 원했던 것은 HTML 페이지에서 특정 필드를 추출하여 데이터베이스에 저장하는 것이 었습니다. –

+0

@ Nishi 입력란에 데이터를 입력 했습니까? 게시물을 보내거나 요청을 받습니까? – Gabs00

관련 문제