2016-10-14 3 views
0

HTML 태그를 제거하려고하는 텍스트 파일이 있습니다. 각 파일에 보존 할 텍스트는 <TEXT></TEXT> 사이입니다. 이 파일 중 일부에는 두 번째 인스턴스 인 <TEXT></TEXT>이 문서의 아래쪽 절반에 보존되어 있습니다.HTML 태그의 여러 세트에서 텍스트를 추출하려면 어떻게해야합니까?

HTML::Restrict은 첫 번째 인스턴스의 모든 관련 텍스트를 보존하는 데 적합하지만 두 번째 인스턴스 인 <TEXT></TEXT> 사이에는 텍스트가 유지되지 않습니다.

내 코드입니다 : 나는 HTML 내에서 어떤 옵션을 식별 할 수

$hr = HTML::Restrict->new() ; 
$processed = $hr->process($doc) ; 

:: 내가 텍스트 파일의 두 번째 부분이 보존 될 수 있도록 조정할 수있는 모듈을 제한합니다. 그러한 옵션이 존재합니까? 아니면이 작업을 수행하는 더 좋은 방법이 있습니까? 일부 정규식을 시도했지만 지금까지 비슷한 문제가 발생했습니다.

아래는 원본 파일입니다. 결과 출력은 모두 <TEXT>의 첫 번째 인스턴스 ('미국'바로 위)이고 첫 번째 인스턴스는 </TEXT>이며 아래쪽의 세 번째 회색 상자에 있습니다.

-----BEGIN PRIVACY-ENHANCED MESSAGE----- 
Proc-Type: 2001,MIC-CLEAR 
Originator-Name: [email protected] 
Originator-Key-Asymmetric: 
MFgwCgYEVQgBAQICAf8DSgAwRwJAW2sNKK9AVtBzYZmr6aGjlWyK3XmZv3dTINen 
TWSM7vrzLADbmYQaionwg5sDW3P6oaM5D3tdezXMm7z1T+B+twIDAQAB 
MIC-Info: RSA-MD5,RSA, 
VlTZCBM7TRNLONv/I0OgPsjKD23uR2Zn9/jJ4XrBQY8DlPxfH2+iX+W5TZjhZEQY 
shGRyuAw29phAaxb1IPhgQ== 

<SEC-DOCUMENT>0001157523-06-001366.txt : 20060209 
<SEC-HEADER>0001157523-06-001366.hdr.sgml : 20060209 
<ACCEPTANCE-DATETIME>20060209161745 
ACCESSION NUMBER:  0001157523-06-001366 
CONFORMED SUBMISSION TYPE: 8-K 
PUBLIC DOCUMENT COUNT:  2 
CONFORMED PERIOD OF REPORT: 20060209 
ITEM INFORMATION:  Results of Operations and Financial Condition 
ITEM INFORMATION:  Financial Statements and Exhibits 
FILED AS OF DATE:  20060209 
DATE AS OF CHANGE:  20060209 

FILER: 

    COMPANY DATA: 
     COMPANY CONFORMED NAME:   ANALOG DEVICES INC 
     CENTRAL INDEX KEY:   0000006281 
     STANDARD INDUSTRIAL CLASSIFICATION: SEMICONDUCTORS & RELATED DEVICES [3674] 
     IRS NUMBER:    042348234 
     STATE OF INCORPORATION:   MA 
     FISCAL YEAR END:   1205 

    FILING VALUES: 
     FORM TYPE:  8-K 
     SEC ACT:  1934 Act" 
     SEC FILE NUMBER: 001-07819 
     FILM NUMBER:  06593279 

    BUSINESS ADDRESS: 
     STREET 1:  ONE TECHNOLOGY WAY 
     CITY:   NORWOOD 
     STATE:   MA 
     ZIP:   02062 
     BUSINESS PHONE:  7813294700 

    MAIL ADDRESS: 
     STREET 1:  ONE TECHNOLOGY WAY 
     CITY:   NORWOOD 
     STATE:   MA 
     ZIP:   02062 
</SEC-HEADER> 
<DOCUMENT> 
<TYPE>8-K 
<SEQUENCE>1 
<FILENAME>a5077045.txt 
<DESCRIPTION>ANALOG DEVICES, INC., 8-K 
<TEXT> 

            UNITED STATES 
         SECURITIES AND EXCHANGE COMMISSION 
          Washington, D.C. 20549 

            FORM 8-K 

           CURRENT REPORT 
    Pursuant to Section 13 OR 15(d) of The Securities Exchange Act of 1934 


Date of Report (Date of earliest event reported): February 9, 2006 

           Analog Devices, Inc. 
- -------------------------------------------------------------------------------- 
      (Exact name of registrant as specified in its charter) 

     Massachusetts    1-7819     04-2348234 
- -------------------------------------------------------------------------------- 
(State or other juris-   (Commission    (IRS Employer 
diction of incorporation  File Number)   Identification No.) 


    One Technology Way, Norwood, MA       02062 
- -------------------------------------------------------------------------------- 
(Address of principal executive offices)     (Zip Code) 


Registrant's telephone number, including area code: (781) 329-4700 


- -------------------------------------------------------------------------------- 
      (Former name or former address, if changed since last report) 


Check the appropriate box below if the Form 8-K filing is intended to 
simultaneously satisfy the filing obligation of the registrant under any of the 
following provisions (see General Instruction A.2. below): 

|_| Written communications pursuant to Rule 425 under the Securities Act (17 
    CFR 230.425) 

|_| Soliciting material pursuant to Rule 14a-12 under the Exchange Act (17 CFR 
    240.14a-12) 

|_| Pre-commencement communications pursuant to Rule 14d-2(b) under the 
    Exchange Act (17 CFR 240.14d-2(b)) 

|_| Pre-commencement communications pursuant to Rule 13e-4(c) under the 
    Exchange Act (17 CFR 240.13e-4(c)) 


<PAGE> 


Item 2.02. Results of Operations and Financial Condition 

    On February 9, 2006, Analog Devices, Inc. announced its financial results 
for the quarter ended January 28, 2006. The full text of the press release 
issued in connection with the announcement is attached as Exhibit 99.1 to this 
Current Report on Form 8-K. 

    The information in this Form 8-K and the exhibit attached hereto shall not 
be deemed "filed" for purposes of Section 18 of the Securities Exchange Act of 
1934 (the "Exchange Act") or otherwise subject to the liabilities of that 
section, nor shall it be deemed incorporated by reference in any filing under 
the Securities Act of 1933 or the Exchange Act, except as expressly set forth by 
specific reference in such a filing. 



            EXHIBIT INDEX 

Exhibit No.    Description 
- -----------    ----------- 

99.1      Press release dated February 9, 2006 issued by Analog 
          Devices, Inc. 
</TEXT> 
</DOCUMENT> 
<DOCUMENT> 
<TYPE>EX-99.1 
<SEQUENCE>2 
<FILENAME>a5077045ex99_1.txt 
<DESCRIPTION>EXHIBIT 99.1 
<TEXT> 
                    Exhibit 99.1 


        Analog Devices Reports Results for the 
         First Quarter of Fiscal Year 2006 

    NORWOOD, Mass.--(BUSINESS WIRE)--Feb. 9, 2006--Analog Devices, 
Inc. (NYSE: ADI): 

    -- Board of Directors declares dividend of $0.12 per share for 
     the quarter. 

    -- Financial results for the first quarter and guidance for the 
     second quarter to be discussed on conference call today at 
     4:30 pm. 

    Analog Devices, Inc. (NYSE: ADI), a global leader in 
high-performance semiconductors for signal processing applications, 
today announced revenue of $621.3 million for the first quarter of 
fiscal 2006, an increase of 7% compared to the same period one year 
ago and approximately even with the immediately prior quarter's $622.1 
million in revenue. 



    CONTACT: Analog Devices, Inc. 
      Maria Tagliaferro,781-461-3282 
      Director of Corporate Communications, 
      781-461-3491 (fax) 
      [email protected] 
</TEXT> 
</DOCUMENT> 
</SEC-DOCUMENT> 
-----END PRIVACY-ENHANCED MESSAGE----- 
+3

질문을 입력하고 입력 예제를 포함하십시오. – simbabque

+0

@simbabque하지만 질문에 원본 파일을 붙여 넣으려고하면 예제 HTML 태그 "<>"가 내 게시물의 내용을 차단하지 않도록하려면 어떻게해야합니까? – Rick

+0

@Rick 코드를 붙여넣고 강조 표시 한 다음 편집기에서'{}'버튼을 클릭하거나 Ctrl + K를 누릅니다. 코드 블록 (이미 한 번 사용한 코드 블록)으로 처리합니다. 또한 [서식 도움말] (http://stackoverflow.com/help/formatting)을보고 [편집] 버튼을 클릭하여 원시 Markdown이 어떻게 보이는지 확인할 수 있습니다. – ThisSuitIsBlackNot

답변

2

, 당신은 던져 각종 쓰레기에 의해 던져진되지 않는 파서를 원하는 그것.

아래 예에서는 편의상 내 스크립트의 __DATA__ 섹션에 위의 샘플 텍스트를 넣었습니다. 현실 세계에서는 적절한 인코딩으로 파일을 열어야합니다.

#!/usr/bin/env perl 

use strict; 
use warnings; 

use HTML::TokeParser::Simple; 

my $parser = HTML::TokeParser::Simple->new(handle => \*DATA); 

my @text; 

while (my $token = $parser->get_token) { 
    if ($token->is_start_tag('text')) { 
     push @text, $parser->get_text('/text'); 
    } 
} 

print "[[[>>>$_<<<]]]\n\n" for @text; 

__DATA__ 
+0

"정의되지 않은 값에서"get_token "메서드를 호출 할 수 없습니다."라는 오류 메시지가 나타납니다. my $ text 변수에 치료하기를 원하는 원시 데이터가 있는지 확인했습니다. 그 문제가 어떤 생각일까요? – Rick

+0

그건'$ parser' 구조가 실패했다는 것을 의미합니다. 파일의 내용을 스칼라에 넣으면'my $ parser = HTML :: TokeParser :: Simple-> new (string => $ html_string);'[docs] (https://metacpan.org/)를 보라. pod/HTML :: TokeParser :: Simple # new-source_type-source). –

+1

예, 원래 코드가 스칼라가 아닌 파일을 참조 할 때 작동하는 것을 확인했습니다. 내 문제가 해결 된 것 같아. 감사! – Rick

1

이렇게하면 모든 일치를 (자신을 테스트) 제공해야합니다 : 당신이 정말로 HTML 문서를 가지고 있지 않기 때문에

my @text = $doc =~ /<TEXT>(.*?)<\/TEXT>/gs 
+0

나는 나를 위해이 일을 할 수 없기 때문에 나는 여기에서 오류를 만들어야 만한다. 적어도, @text의 내용을 인쇄하려고하면 아무 것도 인쇄되지 않습니다. – Rick

+0

@ text = $ doc = ~/ (. *?) <\/TEXT>/gs; foreach (@ 텍스트) { 인쇄 "$ _ \ n"; } – Rick

+0

그 시점 이전에'@ text'를 선언 했습니까? 그렇지 않다면'my @text = ... '가 필요합니다. 그렇다면, HTML 내용이'$ doc'에 있는지 확인 하시겠습니까? –

관련 문제