newspaper icon indicating copy to clipboard operation
newspaper copied to clipboard

Date extraction is faulty

Open inspectorG4dget opened this issue 1 year ago • 2 comments

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

inspectorG4dget avatar Mar 10 '23 14:03 inspectorG4dget

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.

johnbumgarner avatar Mar 17 '23 16:03 johnbumgarner

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

AndyTheFactory avatar Oct 30 '23 11:10 AndyTheFactory