Skip to content

Instantly share code, notes, and snippets.

@inks007
Forked from kaithar/crunchyflare.py
Last active September 4, 2018 21:12
Show Gist options
  • Save inks007/0923fcad02b559600663720f38712553 to your computer and use it in GitHub Desktop.
Save inks007/0923fcad02b559600663720f38712553 to your computer and use it in GitHub Desktop.
Cloudflare is a lovely thing when I'm not trying to work around it...
import cfscrape
import http.cookiejar
from bs4 import BeautifulSoup
scraper = cfscrape.create_scraper()
try:
import config
scraper.headers["User-Agent"] = config.UA
except:
# Oh well
pass
response = scraper.get("https://www.crunchyroll.com/login")
#print(scraper.cookies)
cj = http.cookiejar.MozillaCookieJar('cookies.txt')
for c in scraper.cookies:
cj.set_cookie(c)
soup = BeautifulSoup(response.text)
token = soup.find('input', {'name':'login_form[_token]'})['value']
#print(token)
payload = {
"login_form[name]": "YOUR_USERNAME",
"login_form[password]": "YOUR_PASSWORD",
"login_form[redirect_url]": "/",
"login_form[_token]": token
}
scraper.post("https://www.crunchyroll.com/login", cookies=cj, data=payload)
for c in scraper.cookies:
cj.set_cookie(c)
print(cj)
print(scraper.headers["User-Agent"])
cj.save('cookies.txt', True, True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment