Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blogger / Blogspot issue #847

Open
ontopicprojects opened this issue Oct 5, 2020 · 2 comments
Open

Blogger / Blogspot issue #847

ontopicprojects opened this issue Oct 5, 2020 · 2 comments

Comments

@ontopicprojects
Copy link

Some blogspot / blogger sites don't seem to parse: here is an example:

`from newspaper import Article

url = 'http://www.righto.com/2011/07/cells-are-very-fast-and-crowded-places.html'

article = Article(url)
article.download()
article.parse()
print(article.text)`

this prints ""

@johnbumgarner
Copy link

johnbumgarner commented Oct 8, 2020

The primary reason that you cannot extract from this site with Newspaper is because the tags commonly queried by this module do not exist on the website http://www.righto.com. You should use the Python libraries requests and BeautifulSoup to extract the items that you want.

@AndyTheFactory
Copy link

you can achieve this with some minor changes.

  1. the cleaners class must be fixed (it removes itemprop containing articleBody if it is not exactly "articleBody") see fix itemprop containing articleBody #953
  2. extend the extractor class and replace it in your article 👍
class myExtractor(ContentExtractor):
    def nodes_to_check(self, doc):
        generator = self.parser.getElementsByTag(doc, tag='meta', attr={'name':'generator'})
        for t in generator:
            if t.attrib.get('content') == 'blogger':
                nodes = self.parser.getElementsByTag(doc, tag='div', attr={'class':'post-body'})
                return nodes
        return super().nodes_to_check(doc)

and


a = Article('http://www.righto.com/2011/07/cells-are-very-fast-and-crowded-places.html')
a.extractor = myExtractor(a.config)
a.download()
a.parse()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants