Skip to content

Repository files navigation

article-parser

GitHub Repo starspythonpypiwheellicensePyPI - Downloads

Extract article or news by url or html, parse the title and content.

English简体中文

How to install

article-parser is available on pypi https://pypi.org/project/article-parser/

$ pip install article-parser

Basic Usage

>>>importarticle_parserarticle_parser.parse(
url='', # The URL of the article.html='', # The HTML of the article.threshold=0.9, # The ratio of text to the entire document, default 0.9.output='html', # Result output format, support ``markdown`` and ``html``, default ``html``.**kwargs# Optional arguments that `request` takes. optional
),
## ouput markdown>>>title, content=article_parser.parse(url="http://www.chinadaily.com.cn/a/202009/22/WS5f6962b2a31024ad0ba7afcb.html", output='markdown', timeout=5)
## output html>>>title, content=article_parser.parse(url="http://www.chinadaily.com.cn/a/202009/22/WS5f6962b2a31024ad0ba7afcb.html", timeout=5)

Example

Djokovic wins record 36th Masters title in Rome - Chinadaily.com.cn

  • Markdown
>>>importarticle_parser>>>title, content=article_parser.parse(url="http://www.chinadaily.com.cn/a/202009/22/WS5f6962b2a31024ad0ba7afcb.html", output='markdown', timeout=5)
>>>print(title)
>>>print('----------------')
>>>print(content)
Djokovicwinsrecord36thMasterstitleinRome----------------
![](http://img2.chinadaily.com.cn/images/202009/22/5f6962b2a31024adbd959228.jpeg)
Serbia'sNovakDjokovickissesthetrophyafterwinningthefinalagainstArgentina'sDiegoSchwartzmanatItalianOpen, ForoItalico, Rome, Italy, Sept21, 2020. [Photo/Agencies]
ROME-NovakDjokovicwonarecord36thMasterscrownashebeatDiegoSchwartzmaninthemen'sfinaloftheATPItalianOpenonMonday.
Djokovic, theworldnumberoneandthetopseedatthetournament, won7-5,
6-3againstArgentineSchwartzmantolifthis36thMasterstitle, onemorethanRafaelNadal.
TheSerbsaidhedidnotplayhisbesttennisthistimeinRome, butcouldfinditwhenneeded.
SimonaHalep, topseedofthewomen'sdraw, wonherfirsttitleinRomeafterdefendingchampionKarolinaPliskovaoftheCzechRepublicretiredwhiletrailing6-0, 2-1inthefinal.
  • HTML
>>>importarticle_parser>>>title, content=article_parser.parse(url="http://www.chinadaily.com.cn/a/202009/22/WS5f6962b2a31024ad0ba7afcb.html", timeout=5)
>>>print(title)
>>>print('----------------')
>>>print(content)
Djokovicwinsrecord36thMasterstitleinRome----------------<divid="Content"><figureclass="image"style="display: table;"><imgdata-from="newsroom"id="img-5f6962b2a31024adbd959228"src="//img2.chinadaily.com.cn/images/202009/22/5f6962b2a31024adbd959228.jpeg"/><figcaptionstyle="font-size: 14px; display: table-caption; caption-side: bottom;">Serbia's Novak Djokovic kisses the trophy after winning the final against Argentina'sDiegoSchwartzmanatItalianOpen, ForoItalico, Rome, Italy, Sept21, 2020. [Photo/Agencies]
</figcaption></figure><pdir="ltr">ROME-NovakDjokovicwonarecord36thMasterscrownashebeatDiegoSchwartzmaninthemen'sfinaloftheATPItalianOpenonMonday.</p><pdir="ltr">Djokovic, theworldnumberoneandthetopseedatthetournament, won7-5, 6-3againstArgentineSchwartzmantolifthis36thMasterstitle, onemorethanRafaelNadal.</p><pdir="ltr">TheSerbsaidhedidnotplayhisbesttennisthistimeinRome, butcouldfinditwhenneeded.</p><pdir="ltr">SimonaHalep, topseedofthewomen'sdraw, wonherfirsttitleinRomeafterdefendingchampionKarolinaPliskovaoftheCzechRepublicretiredwhiletrailing6-0, 2-1inthefinal.</p></div>

Contributors

All contributions

Stargazers over time

Stargazers over time

About

Extract article or news by url or html, parse the title and content, output in markdown format.

Topics

Resources

Stars

49 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages