Nv7-GitHub / googlesearch

A Python library for scraping the Google search engine.
https://pypi.org/project/googlesearch-python/
MIT License
430 stars 110 forks source link

Fix Incorrect Proxy Setting Usage in Request Module #83

Open t-tani opened 3 weeks ago

t-tani commented 3 weeks ago

Description

The current implementation of the proxy setting in the search function does not handle proxies correctly. Specifically, if a proxy is set with the format http://proxy_host:port, it does not handle https requests to proxy, which is required for Google search.

Related Issues

73

Solution

This PR updates the proxy setting logic to correctly configure the proxy for both http and https protocols when the proxy URL starts with http:// or https://. This ensures that https requests are properly routed through the proxy even when the proxy URL is specified with http://.

Changes Made

Updated the proxy setting logic to configure proxies for both http and https protocols properly.

Old Code

if proxy:
    if proxy.startswith("https"):
        proxies = {"https": proxy}
    else:
        proxies = {"http": proxy}

New Code

if proxy.startswith("http://") or proxy.startswith("https://"):
    proxies = {
        "https": proxy,
        "http": proxy
    }