Skip to content

Instantly share code, notes, and snippets.

@ekisu
Last active May 23, 2017 21:37
Show Gist options
  • Save ekisu/ac77abb91e58374499651a876aaca062 to your computer and use it in GitHub Desktop.
Save ekisu/ac77abb91e58374499651a876aaca062 to your computer and use it in GitHub Desktop.
Test language bug
import requests
from bs4 import BeautifulSoup
def parse_language(response):
return BeautifulSoup(response.text).find("html")['lang']
def open_page_accept_language():
headers = {"accept-language": "pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4"}
response = requests.get("https://sukebei.pantsu.cat", headers=headers)
return parse_language(response)
i = 0
results = {}
while i < 1000:
lang = open_page_accept_language()
print "%i try, got %s" % (i, lang)
if lang in results:
results[lang] = results[lang] + 1
else:
results[lang] = 1
i += 1
for lang in results:
print "%s, %i times" % (lang, results[lang])
import requests
from bs4 import BeautifulSoup
def parse_language(response):
return BeautifulSoup(response.text).find("html")['lang']
def open_page_cookies():
headers = {"accept-language": "pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4"}
cookies = {"lang": "it-it"}
response = requests.get("https://sukebei.pantsu.cat", headers=headers, cookies=cookies)
return parse_language(response)
i = 0
results = {}
while i < 1000:
lang = open_page_cookies()
print "%i try, got %s" % (i, lang)
if lang in results:
results[lang] = results[lang] + 1
else:
results[lang] = 1
i += 1
for lang in results:
print "%s, %i times" % (lang, results[lang])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment