Google News Decoder

repository·main·Indexed 42 days ago

https://github.com/ssujitx/google-news-url-decoder

A Python package, googlenewsdecoder, designed to decode Google News URLs back to their original source URLs. It features the gnewsdecoder function with built-in support for request intervals and various proxy formats, including HTTP, HTTPS, and SOCKS5, to help users avoid rate limiting.

Tokens
1.5K
Snippets
3
Records
4
Agent score
5%

What's inside Google News Decoder

  1. Install googlenewsdecoder via pip

    main

    You can install the googlenewsdecoder package using pip. To upgrade to the latest version, use the --upgrade flag.

    # Install the package
    pip install googlenewsdecoder
    
    # Upgrade to the latest version
    pip install googlenewsdecoder --upgrade
    pip install googlenewsdecoder
  2. Decode multiple URLs with a loop

    main

    To process a list of Google News URLs, iterate through the list and call gnewsdecoder for each item. You can also pass a proxy and an interval to manage rate limiting during batch processing.

    from googlenewsdecoder import gnewsdecoder
    
    source_urls = [
        "https://news.google.com/read/URL_1",
        "https://news.google.com/read/URL_2"
    ]
    proxy = "http://user:pass@localhost:8080"
    
    for url in source_urls:
        try:
            decoded_url = gnewsdecoder(url, interval=1, proxy=proxy)
            if decoded_url.get("status"):
                print("Decoded URL:", decoded_url["decoded_url"])
            else:
                print("Error:", decoded_url["message"])
        except Exception as e:
            print(f"Error occurred: {e}")
    from googlenewsdecoder import gnewsdecoder
    
    def main():
        interval_time = 1
        proxy = "http://user:pass@localhost:8080"
    
        source_urls = [
            "https://news.google.com/read/CBMilgFBVV95cUxOM0JJaFRwV2dqRDk5dEFpWmF1cC1IVml5WmVtbHZBRXBjZHBfaUsyalRpa1I3a2lKM1ZnZUI4MHhPU2sydi1nX3JrYU0xWjhLaHNfU0N6cEhOYVE2TEptRnRoZGVTU3kzZGJNQzc2aDZqYjJOR0xleTdsemdRVnJGLTVYTEhzWGw4Z19lR3AwR0F1bXlyZ0HSAYwBQVVfeXFMTXlLRDRJUFN5WHg3ZTI0X1F4SjN6bmFIck1IaGxFVVZyOFQxdk1JT3JUbl91SEhsU0NpQzkzRFdHSEtjVGhJNzY4ZTl6eXhESUQ3XzdWVTBGOGgwSmlXaVRmU3BsQlhPVjV4VWxET3FQVzJNbm5CUDlUOHJUTExaME5YbjZCX1NqOU9Ta3U?hl=en-US&gl=US&ceid=US%3Aen",
            "https://news.google.com/read/CBMiiAFBVV95cUxQOXZLdC1hSzFqQVVLWGJVZzlPaDYyNjdWTURScV9BbVp0SWhFNzZpSWZxSzdhc0tKbVlHMU13NmZVOFdidFFkajZPTm9SRnlZMWFRZ01CVHh0dXU0TjNVMUxZNk9Ibk5DV3hrYlRiZ20zYkIzSFhMQVVpcTFPc00xQjhhcGV1aXM00gF_QVVfeXFMTmtFQXMwMlY1el9WY0VRWEh5YkxXbHF0SjFLQVByNk1xS3hpdnBuUDVxOGZCQXl1QVFXaUVpbk5lUGgwRVVVT25tZlVUVWZqQzc4cm5MSVlfYmVlclFTOUFmTHF4eTlfemhTa2JKeG14bmNabENkSmZaeHB4WnZ5dw?hl=en-US&gl=US&ceid=US%3Aen"
        ]
    
        for url in source_urls:
            try:
                decoded_url = gnewsdecoder(url, interval=interval_time, proxy=proxy)
                if decoded_url.get("status"):
                    print("Decoded URL:", decoded_url["decoded_url"])
                else:
                    print("Error:", decoded_url["message"])
            except Exception as e:
                print(f"Error occurred: {e}")
    
    if __name__ == "__main__":
        main()
  3. Use the gnewsdecoder function

    main

    The core function gnewsdecoder takes a Google News source URL and returns a dictionary containing the decoding status and the resulting URL.

    Parameters:

    • source_url (str): The Google News URL to decode.
    • interval (int, optional): Time interval between requests. Defaults to None.
    • proxy (str, optional): Proxy URL in one of the supported formats. Defaults to None.

    Return Value (dict):

    • status (bool): Indicates if the decoding was successful.
    • decoded_url (str): The original URL (present if status is True).
    • message (str): Error message (present if status is False).
    from googlenewsdecoder import gnewsdecoder
    
    source_url = "https://news.google.com/read/..."
    
    try:
        decoded_url = gnewsdecoder(source_url, interval=1)
    
        if decoded_url.get("status"):
            print("Decoded URL:", decoded_url["decoded_url"])
        else:
            print("Error:", decoded_url["message"])
    except Exception as e:
        print(f"Error occurred: {e}")
  4. Supported Proxy Formats

    main

    The gnewsdecoder function supports several proxy formats to help handle rate limiting and bypass restrictions. Supported protocols include HTTP, HTTPS, and SOCKS5, both with and without authentication.

    HTTP/HTTPS Proxies

    • With authentication: http://user:pass@host:port or https://user:pass@host:port
    • Without authentication: http://host:port or https://host:port

    SOCKS5 Proxies

    • With authentication: socks5://user:pass@host:port
    • Without authentication: socks5://host:port

    IP and Port Only

    • HTTP: http://127.0.0.1:8080
    • SOCKS5: socks5://127.0.0.1:1080