Fetches the IP address of the machine associated with the given URL using Scrape.do. Args: token (str): The API token for Scrape.do service. target_url (str): A valid web page URL to fetch its associated IP address. use_proxy (bool): Whether to use Scrape.do proxy m
(
token, target_url, use_proxy=False, geoCode=None, super_proxy=False
)
| 12 | |
| 13 | |
| 14 | def scrape_do_fetch( |
| 15 | token, target_url, use_proxy=False, geoCode=None, super_proxy=False |
| 16 | ): |
| 17 | """ |
| 18 | Fetches the IP address of the machine associated with the given URL using Scrape.do. |
| 19 | |
| 20 | Args: |
| 21 | token (str): The API token for Scrape.do service. |
| 22 | target_url (str): A valid web page URL to fetch its associated IP address. |
| 23 | use_proxy (bool): Whether to use Scrape.do proxy mode. Default is False. |
| 24 | geoCode (str, optional): Specify the country code for |
| 25 | geolocation-based proxies. Default is None. |
| 26 | super_proxy (bool): If True, use Residential & Mobile Proxy Networks. Default is False. |
| 27 | |
| 28 | Returns: |
| 29 | str: The raw response from the target URL. |
| 30 | """ |
| 31 | encoded_url = urllib.parse.quote(target_url) |
| 32 | if use_proxy: |
| 33 | proxy_scrape_do_url = os.getenv("PROXY_SCRAPE_DO_URL", "proxy.scrape.do:8080") |
| 34 | proxy_mode_url = f"http://{token}:@{proxy_scrape_do_url}" |
| 35 | proxies = { |
| 36 | "http": proxy_mode_url, |
| 37 | "https": proxy_mode_url, |
| 38 | } |
| 39 | params = ( |
| 40 | {"geoCode": geoCode, "super": str(super_proxy).lower()} if geoCode else {} |
| 41 | ) |
| 42 | response = requests.get( |
| 43 | target_url, proxies=proxies, verify=False, params=params |
| 44 | ) |
| 45 | else: |
| 46 | api_scrape_do_url = os.getenv("API_SCRAPE_DO_URL", "api.scrape.do") |
| 47 | url = f"http://{api_scrape_do_url}?token={token}&url={encoded_url}" |
| 48 | response = requests.get(url) |
| 49 | |
| 50 | return response.text |