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 #484

Closed
AndyTheFactory opened this issue Oct 24, 2023 · 3 comments
Closed

Blogger / Blogspot issue #484

AndyTheFactory opened this issue Oct 24, 2023 · 3 comments

Comments

@AndyTheFactory
Copy link
Owner

Issue by ontopicprojects
Mon Oct 5 15:37:20 2020
Originally opened as codelucas/newspaper#847


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 ""

@AndyTheFactory
Copy link
Owner Author

Comment by johnbumgarner
Thu Oct 8 03:50:57 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
Owner Author

Comment by AndyTheFactory
Tue Oct 4 16:28:18 2022


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 codelucas/newspaper#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()

@AndyTheFactory
Copy link
Owner Author

Works in v0.9.1

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

No branches or pull requests

1 participant