텍스트만 출력하는 브라우저와 유사한 리더 모드

텍스트만 출력하는 브라우저와 유사한 리더 모드

배경:리더 모드, Safari 및 기타 브라우저에 표시된 것처럼 추출메인 콘텐츠~의기사를 기반으로웹 페이지는 정교한 경험적 방법을 사용하며 매우 읽기 쉬운 글꼴로 표시됩니다.

모든 탐색, 머리글, 바닥글 및 기타 콘텐츠가 제거됩니다. 이 모드는 "기사"에만 작동합니다. 뉴스 기사, 과학 논문 등 '주요 콘텐츠'가 포함된 페이지

질문: 거기에오픈 소스터미널 구현(예: 일반 텍스트)? 아니면 동일한 작업을 수행하는 다른 방법이 있습니까?

예: 이 New York Times 기사는 다음을 출력해야 합니다.

$ utility --reader-mode https://www.nytimes.com/2019/01/30/reader-center/polar-vortex-tips.html

SEND US YOUR IDEAS FOR WHAT TO DO DURING THE POLAR VORTEX. WE
WANT TO HEAR FROM YOU.

It’s so cold in much of the Midwest today that you could get
frostbite within five minutes once you step outside. If you’re
living through it indoors, give us your tips.

A commuter during an extremely light morning rush hour in Chicago
on Wednesday. Businesses and schools have closed as the city
copes with record low temperatures.

Across the Midwest, where wind chills were minus 51 in
Minneapolis and minus 45 in Chicago, the risks of going outside
on Wednesday were dire. So, many people simply didn’t bother,
while others took a chance to briefly experience the coldest
weather in a generation.

Whether you’re an adventurer or a hibernator, tell us your
recommendations for staying warm and busy. What are you cooking
or binge-watching? What board games are you playing? If you’re
venturing outside, what are you doing to stay safe? (Experts warn
that even a short time in the extreme cold can be very
dangerous.) How many layers of clothing are you wearing, and
which special hats and gloves are necessary? Send us your photos
and your stories.

답변1

나는 가독성-cli(https://gitlab.com/gardenappl/readability-cli) 및 판독(https://pandoc.org/). 예를 들어

% readable https://www.nytimes.com/2019/01/30/reader-center/polar-vortex-tips.html | pandoc -f html - -t plain
Send Us Your Ideas for What to Do During the Polar Vortex. We Want to Hear From You.

It’s so cold in much of the Midwest today that you could get frostbite
within five minutes once you step outside. If you’re living through it
indoors, give us your tips.

[Credit...Scott Olson/Getty Images]

Across the Midwest, where wind chills were minus 51 in Minneapolis and
minus 45 in Chicago, the risks of going outside on Wednesday were dire.
So, many people simply didn’t bother, while others took a chance to

등. 이것은 Node 프로젝트이므로 사람들은 종속성의 취약성에 대해 알고 싶어하므로 스스로 판단하십시오. (아이러니하게도 이 페이지와 같은 stackexchange.com 링크에서는 제대로 작동하지 않습니다 :-)

답변2

에 대한 코멘트"내비게이션 콘텐츠"에 의해-nolist다음과 같은 옵션

lynx -nolist -dump www.google.com > file.txt

링크 등은 표시되지 않습니다.

$ lynx -nolist -dump www.google.com > file.txt
$ cat file.txt 

   Search Images Maps Play YouTube News Gmail Drive More »
   Web History | Settings | Sign in

   Google

     _______________________________________________________
     Google Search  I'm Feeling Lucky                          Advanced search
                                                               Language tools

   Advertising Programs       Business  Solutions       +Google     About
   Google

                         © 2019 - Privacy - Terms

w3m다음과 같은 내용을 제공하지만 옵션은 없습니다.

$ w3m -dump https://www.google.com
Search Images Maps Play YouTube News Gmail Drive More >>
Web History | Settings | Sign in

                                    Google

           [                                                         ] Advanced
                                                                       searchLanguage
                       [Google Search][I'm Feeling Lucky]              tools

           Advertising ProgramsBusiness Solutions+GoogleAbout Google

                          (C) 2019 - Privacy - Terms

links2출력은 다음과 같습니다.w3m(앞에 누락된 공간이 있음을 참고하세요.~에 대한):

$ links2 -dump www.google.com                                          
   Search Images Maps Play YouTube News Gmail Drive More >>========(97,1) 31% ==
   Web History | Settings | Sign in                                             
                                     Google

    __________________________________________________________    Advanced       
              [ Google Search ] [ I'm Feeling Lucky ]             searchLanguage 
                                                                  tools          

           Advertising ProgramsBusiness Solutions+GoogleAbout Google

                           (c) 2019 - Privacy - Terms

$ links2 -dump www.google.com >file.txt 
$ cat file.txt 
   Search Images Maps Play YouTube News Gmail Drive More >>
   Web History | Settings | Sign in
                                     Google

    __________________________________________________________    Advanced       
              [ Google Search ] [ I'm Feeling Lucky ]             searchLanguage 
                                                                  tools          

           Advertising ProgramsBusiness Solutions+GoogleAbout Google

                           (c) 2019 - Privacy - Terms

(이상하게도 덤프가 터미널로 직접 들어가면 진행 상황도 인쇄됩니다. 좋은 기능은 아닙니다.)elinks분명히 "탐색 콘텐츠"가 있는 형식만 덤프됩니다(ymmv).

추가 댓글을 보면 OP가 주어진 콘텐츠를 렌더링할 수 있는 것에 관심이 있었던 것으로 나타났습니다.분배하다페이지에서. 사이즈 비교원천그리고덤프이 페이지는 몇 가지 단서를 제공합니다.

      크기 버퍼 이름 내용
      ------- ------- ---------- ------------------------------------- ----------------
   0# 267624 [!lynx -source ht-1] !lynx -source https://www.nytimes.com/2019/01/30/reader-center/폴라-vortex-tips.html
   1 5475 [!lynx -dump -nolis] !lynx -dump -nolist https://www.nytimes.com/2019/01/30/reader-center/폴라-vortex-tips.html

표시된 덤프는 소스 크기의 약 2%입니다. 페이지 콘텐츠의 대부분은 정보를 제공하지 않으며 텍스트 브라우저에 정보가 표시됩니다. 하지만분배하다요청된 것은 다음과 같은 두 줄 블록입니다(시작 부분만 해당: 첫 번째 줄은 실제로62265수치):

<div id="app"><div class="css-v89234 e3w10z60"><div><div><div class="css-13lpfd6 e1nre7570"><header class="css-1bymuyk e1>
<script>window.__preloadedData = {"initialState":{"Article:QXJ0aWNsZTpueXQ6Ly9hcnRpY2xlLzBhODc0MTcxLWM0MjEtNWRjOS1hN2IzLW>

첫 번째 줄에는 기사 텍스트(많은 마크업 포함)가 포함되어 있습니다. 두 번째 줄은 GUI 브라우저에서 감지된 대로 기사를 표시하는 데 사용되는 스크립트일 수 있으므로 자유롭게 살펴보세요. 위의 텍스트 브라우저 중 어느 것도 주어진 스크립트를 표시하거나 이런 방식으로 해석하는 기능을 가지고 있지 않습니다 <div>...</div>. 이 기사에서는 여러 GUI 브라우저에서 리더 모드에 대한 표준 URI가 부족하다고 언급합니다.

답변3

이것이 귀하의 요구 사항을 충족합니까? (에서https://stackoverflow.com/questions/12422289/bash-command-to-convert-html-page-to-a-text-file)

lynx --dump www.google.com > file.txt

관련 정보