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

Date extraction is faulty #967

Open
inspectorG4dget opened this issue Mar 10, 2023 · 2 comments
Open

Date extraction is faulty #967

inspectorG4dget opened this issue Mar 10, 2023 · 2 comments

Comments

@inspectorG4dget
Copy link

The publication date of this article is reported as 2023-12-10. This is impossible, as the article is downloaded on 2023-03-10. The article lists it's own publication date as 2023-01-02.

Further investigation shows that the article was "accepted for publication" on 2022-12-16 (which might explain where the 12 comes from).
The HTML source code shows

    <meta name="dc.date" content="2023-01-02"/>

So it is unclear what's causing this error, but the error itself is confirmed

@johnbumgarner
Copy link

I have no direct affiliation with this project and this project is very stagnant by its owner. Since the project is stagnant it has LOTS of bugs, such as the one you found for the article in question.

This bug is in the extractors module, which has the Class ContentExtractor.

Below is the section of code that caused your bug.

 def parse_date_str(date_str):
            if date_str:

            # THE return date_str is 2023/12
               
                try:

                   # date_parser(date_str) returns this
                   # 2023-12-17 00:00:00

                    return date_parser(date_str)
                except (ValueError, OverflowError, AttributeError, TypeError):
                    # near all parse failures are due to URL dates without a day
                    # specifier, e.g. /2014/04/
                    return None

        date_match = re.search(urls.STRICT_DATE_REGEX, url)
        if date_match:
            date_str = date_match.group(0)
            datetime_obj = parse_date_str(date_str)
            if datetime_obj:
                return datetime_obj

The only way to fix this issue is either request the date from the meta data for the article or patch the code in your development environment.

@AndyTheFactory
Copy link

Hi @inspectorG4dget - i have forked the project and fixed this issue (and some additional ones) .
You can check it out https://github.com/AndyTheFactory/newspaper4k
pip install newspaper4k

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