keepcosmos / readability Goto Github PK
View Code? Open in Web Editor NEWReadability is Elixir library for extracting and curating articles.
License: Apache License 2.0
Readability is Elixir library for extracting and curating articles.
License: Apache License 2.0
The regex used for title suffix detection is too liberal.
~r/(\-)|(\:\:)|(\|)/
For example, it breaks the following titles:
Why all-white kitchens are on their way out
Result: Why all
Why ultra-low interest rates are on the nose
Result: Why ultra
I would suggest that suffix markers only apply if they are bordered by whitespace & only apply the suffix detection to <title>
tag parsing.
I'll prepare a fix.
v: 0.6.1
** (FunctionClauseError) no function clause matching in Floki.DeepText.get_text/3
lib/floki/deep_text.ex:28: Floki.DeepText.get_text(nil, "", "")
lib/readability/helper.ex:75: Readability.Helper.text_length/1
lib/readability/article_builder.ex:38: Readability.ArticleBuilder.build/2
First of all thank you for this library, it's excellent!
Right now there's an issue for pages where the image url is set relative to the url. For example:
<img src="/content//images/2015/04/Hard_disk_Western_Digital_WD1000_1_-dark1-.jpg">
Can there be a way for the images to be set using the full domain path?
Given the following HTML...
<html>
<head>
<meta property='og:title' content='og title 1'>
<meta property='og:title' content='og title 2'>
</head>
<body>
...
</body>
</html>
... the tag finder will return "og title 1og title 2"
. This also occurs for the title tag finder. We should instead only extract the first matching tag.
PR is incoming. 😃
Could you provide an option to Summarize
from Raw HTML?
{:readability, "~> 0.8.0"}
x = Readability.summarize("https://sergiotapia.me/pluralizing-strings-in-javascript-es6-b5d4d651d403")
Error:
15:40:05 web.1 | ** (UndefinedFunctionError) function Floki.Selector.match?/2 is undefined or private. Did you mean one of:
15:40:05 web.1 |
15:40:05 web.1 | * match?/3
15:40:05 web.1 |
15:40:05 web.1 | (floki) Floki.Selector.match?({"html", [], [{"head", [], [{"title", [], ["302 Found"]}]}, {"body", [{"bgcolor", "white"}], [{"center", [], [{"h1", [], ["302 Found"]}]}, {"hr", [], []}, {"center", [], ["nginx"]}]}]}, [%Floki.Selector{attributes: [], classes: [], combinator: nil, id: nil, namespace: nil, pseudo_classes: [], type: "p"}])
15:40:05 web.1 | (readability) lib/readability/helper.ex:84: anonymous fn/2 in Readability.Helper.candidate_tag?/1
15:40:05 web.1 | (elixir) lib/enum.ex:2732: Enum.do_any?/2
15:40:05 web.1 | (readability) lib/readability/candidate_finder.ex:54: Readability.CandidateFinder.candidate?/2
15:40:05 web.1 | (readability) lib/readability/candidate_finder.ex:27: Readability.CandidateFinder.find/3
15:40:05 web.1 | (readability) lib/readability/article_builder.ex:31: Readability.ArticleBuilder.build/2
15:40:05 web.1 | (readability) lib/readability.ex:79: Readability.summarize/2
15:40:05 web.1 | (myapp) lib/news/news.ex:30: MyApp.News.download_content/1
It looks like a 302 redirect error that Readability isn't capturing properly.
This occurs for Readability.TitleFinder.title/1
as well as Readability.TitleFinder.h_tag_title/2
.
PR incoming 😃
iex(4)> require Readability
Readability
iex(5)> url = "http://www.ncbi.nlm.nih.gov/pubmed/22188593"
"http://www.ncbi.nlm.nih.gov/pubmed/22188593"
iex(6)> Readability.summarize(url)
** (FunctionClauseError) no function clause matching in Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:52: Readability.Helper.remove_tag({"version", "1.0"}, #Function<0.72746186/1 in Readability.ArticleBuilder.build/2>)
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/article_builder.ex:24: Readability.ArticleBuilder.build/2
(readability) lib/readability.ex:77: Readability.summarize/2
iex(6)> url = "https://medium.com/@kenmazaika/why-im-betting-on-elixir-7c8f847b58"
"https://medium.com/@kenmazaika/why-im-betting-on-elixir-7c8f847b58"
iex(7)> Readability.summarize(url)
%Readability.Summary{article_html: "<div><div><p id=\"3476\"><strong><em>Background: </em></strong><em>I’ve spent the past 6 years building web applications in Ruby and the Rails framework. I’ve flirted with new programming languages as they came out, but Elixir is the first language that has been able to captivate me.</em> etc etc etc}
The main difference that I see is the <?xml version="1.0" encoding="utf-8"?>
tag at the top of the pubmed link.
I'm pretty new to elixir, but if you have any pointers for fixing this, I'm happy to help!
Thanks.
Readability.TitleFinder.tag_title/1
incorrectly pulls title tags from embedded SVGs. The title tag should only be extracted from <head>
.
Preparing a fix.
May it be possible for you to update Floki to the latest version or are there issues with it? I'd also send a PR if you want, incrementing the number.
Can you please publish the latest commit to Hex.pm? It's behind and the deps are falling behind.
Thanks!
Add more configurable options and write great docs
Support elixir 1.5 and floki 0.18
iex(2)> Readability.summarize("https://www.wired.com/2016/10/review-logitech-keys-go/")
** (FunctionClauseError) no function clause matching in Readability.Helper.remove_tag/2
The following arguments were given to Readability.Helper.remove_tag/2:
# 1
{"echo", "echo"}
# 2
#Function<0.78353828/1 in Readability.ArticleBuilder.build/2>
Attempted function clauses (showing 4 out of 4):
def remove_tag(content, _) when is_binary(content)
def remove_tag([], _)
def remove_tag([h | t], fun)
def remove_tag({tag, attrs, inner_tree} = html_tree, fun)
(readability) lib/readability/helper.ex:52: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:59: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:59: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:59: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:59: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:66: Readability.Helper.remove_tag/2
(readability) lib/readability/helper.ex:55: Readability.Helper.remove_tag/2
Currently in article we do opts = Keyword.merge(@default_options, opts)
, in summarize we don't.
It should be unified - we probably want to use default options also in summarize.
Can summarize it:
iex(6)> Readability.summarize("http://www.techhive.com/article/3158435/home-tech/43-off-tp-link-smart-led-wi-fi-light-bulb-dimmable-and-alexa-compatible-deal-alert.html#tk.rss_smartappliance") %Readability.Summary{article_html: "<div><div id=\"drr-container\"><p>TP-Link has discounted its 50W smart bulb <a href=\"https://www.amazon.com/TP-Link-Dimmable-Equivalent-Amazon-LB100/dp/B01HXM8XF6?psc=1&SubscriptionId=AKIAIRZJHSP2SKQIWVZA&tag=techconnect00-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B01HXM8XF6\" rel=\"nofollow\">43% to just $19.99</a>. Use the Kasa app to turn on/off or dim from anywhere in the world. Set up a schedule, set the mood, and even control with your voice via an Alexa-enabled device such as Echo or Dot. Reviewers rate 4 out of 5 stars (see reviews) on Amazon, where you can get yourself one (or more) for just $20, a good deal considering it typically lists north of $20 and sometimes $30 with various online retailers. <a href=\"https://www.amazon.com/TP-Link-Dimmable-Equivalent-Amazon-LB100/dp/B01HXM8XF6?psc=1&SubscriptionId=AKIAIRZJHSP2SKQIWVZA&tag=techconnect00-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B01HXM8XF6\" rel=\"nofollow\">See the discounted TP-Link smart LED bulb on Amazon</a>.</p><p>This story, \"43% off TP-Link Smart LED Wi-Fi Light Bulb, 50W Dimmable and Alexa Compatible - Deal Alert\" was originally published by\n<span><span><a href=\"http://www.techconnect.com/\" rel=\"nofollow\">TechConnect</a></span></span>.</p><div><div id=\"\">To comment on this article and other TechHive content, visit our <a href=\"https://www.facebook.com/techhivemedia/\">Facebook</a> page or our <a href=\"https://twitter.com/techhive\">Twitter</a> feed. </div></div></div></div>",
article_text: "TP-Link has discounted its 50W smart bulb 43% to just $19.99. Use the Kasa app to turn on/off or dim from anywhere in the world. Set up a schedule, set the mood, and even control with your voice via an Alexa-enabled device such as Echo or Dot. Reviewers rate 4 out of 5 stars (see reviews) on Amazon, where you can get yourself one (or more) for just $20, a good deal considering it typically lists north of $20 and sometimes $30 with various online retailers. See the discounted TP-Link smart LED bulb on Amazon.\nThis story, \"43% off TP-Link Smart LED Wi-Fi Light Bulb, 50W Dimmable and Alexa Compatible - Deal Alert\" was originally published by\nTechConnect.\nTo comment on this article and other TechHive content, visit our Facebook page or our Twitter feed.",
authors: ["DealPost Team"],
title: "43% off TP-Link Smart LED Wi-Fi Light Bulb, 50W Dimmable and Alexa Compatible - Deal Alert"}
Extracting article directly from HTML fails:
iex(6)> Readability.article(HTTPoison.get!("http://www.techhive.com/article/3158435/home-tech/43-off-tp-link-smart-led-wi-fi-light-bulb-dimmable-and-alexa-compatible-deal-alert.html#tk.rss_smartappliance").body)
** (FunctionClauseError) no function clause matching in Floki.HTMLTree.build/1
(floki) lib/floki/html_tree.ex:14: Floki.HTMLTree.build(nil)
(floki) lib/floki/finder.ex:48: Floki.Finder.find_selectors/2
(floki) lib/floki/filter_out.ex:17: Floki.FilterOut.filter_out/2
(floki) lib/floki.ex:210: Floki.text/2
(readability) lib/readability/helper.ex:75: Readability.Helper.text_length/1
(readability) lib/readability/article_builder.ex:32: Readability.ArticleBuilder.build/2
This is because in the second case the "clean_conditionally: true" option is passed to the Sanitizer. Using different options is a bit surprising, nevertheless it should not crash.
{:httpoison, "~> 0.13.0"},
This forces everyone with an updated codebase to use override: true
{:httpoison, "~> 1.5", override: true}
I know it's hard to keep the lib updated, but at least make the dependencies more open for updates
Hi I am having this error while trying to parse this URL http://www.alaskalegislativedigest.com/?p=577, you can reproduce it using
url = "http://www.alaskalegislativedigest.com/?p=577"
with %{status_code: 200, body: raw_html} <- HTTPoison.get!(url) do
raw_html |> Readability.article() |> Readability.readable_text()
end
Now I know the error thrown is in the Floki library but it seemed like Readability is sending the HTML tree as nil to Floki parser.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.