I am trying to scrape websites for valuable text for example the title of an article, the author's name, and other distinguished text. I cannot always guarantee that this sort of text will have informative tags, and but this needs to be done as quickly as possible. As a possible short cut I think that I could just try to pull the text with unique styling. The title is normally bigger than the body text, and the by-line is normally smaller. Is there a way to quickly pull all of the font stylings of a page and then rank them by size and how often it is used?
That seems like a terribly difficult way of doing things due to the need to completely comprehend all the tricks that you can do in CSS. Detecting headings (
<h2>, etc.) would be much easier, and if the target website isn't using them, their site will probably not be being very nicely scraped by search engines either. After all, much of the web is actually about encouraging people to put at least some semantic tags on their pages, and headings are some of the most basic semantic tags (“(this part of) this page is about this topic…”). They might not always use the right headings, but if they never use them at all then it is arguably the case that their page is not about anything much at all.
If you're going to do it otherwise, and you've got a library to do all the CSS parsing for you (don't write your own!) then you'll be best off looking at the
font-size property of text. Bear in mind that some people like styles that distinguish by colour instead, and others change font size all over the place just because they can, but they really are the exception and not the rule: the rule is that people really do use headings, and usually they use them right.
protected by Community♦ Jan 5 '17 at 13:57
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?