codelucas / newspaper

newspaper3k is a news, full-text, and article metadata extraction in Python 3. Advanced docs:
https://goo.gl/VX41yK
MIT License
13.89k stars 2.1k forks source link

Date extraction is faulty #967

Open inspectorG4dget opened 1 year ago

inspectorG4dget commented 1 year ago

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 commented 1 year ago

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 commented 8 months ago

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