禁止使用Python Request + cfscrape Bypass 403

时间:2019-02-21 05:50:58

标签: python python-requests

我正在使用Python Requests + Cfscrape模块绕过启用了Cloudflare的网站,但有时无法验证URL是否正确地带来了403状态标头。 另外,我正在使用Tor代理来查找被阻止的URL

import sys
import requests
import cfscrape

# Create the session and set the proxies.
proxies = {'http': 'socks5://127.0.0.1:9050',
           'https': 'socks5://127.0.0.1:9050'}

# Start Session
#s = requests.Session()
s = cfscrape.create_scraper() # https://github.com/Anorov/cloudflare-scrape/issues/103
# Proxy Connection
s.proxies = proxies
# Bypass Cloudflare Enabled website - https://support.cloudflare.com/hc/en-us/articles/203306930-Does-Cloudflare-block-Tor-
scraper = cfscrape.create_scraper(sess=s, delay=10)


try:
    #user input
    LINK = input('Enter a URL: ')
    response = scraper.get(LINK)
except requests.ConnectionError as e:
    print("OOPS!! Connection Error - May be the URL is Not Valid or Can't Bypass them")
except requests.Timeout as e:
    print("OOPS!! Timeout Error")
except requests.RequestException as e:
    print("OOPS!! General Error (Enter a Valid URL) - Add HTTP/HTTPS infront of the URL")
except (KeyboardInterrupt, SystemExit):
    print("Ok ok, quitting")
    sys.exit(1)
else:
    if response.history:
        print("URL was redirected")
    for resp in response.history:
        print(resp.status_code, resp.url)
        print("Final destination:")
        print(response.status_code, response.url)
        break
    else:
        print(response.status_code, response.url + " - Current Live and Active URL")

0 个答案:

没有答案