from trafilatura import extract, fetch_url
import json

urls = [
    'https://en.wikipedia.org/wiki/Python',
    'https://www.sohu.com/a/1028742089_121106994',
]

for url in urls:
    try:
        downloaded = fetch_url(url)
        if downloaded:
            text = extract(downloaded)
            if text:
                print(f'OK [{url[:45]}]: {text[:100]}')
            else:
                print(f'FAIL [{url[:45]}]: extract returned None')
        else:
            print(f'FAIL [{url[:45]}]: fetch failed')
    except Exception as e:
        print(f'ERR  [{url[:45]}]: {e}')
