Last active
May 23, 2017 21:37
-
-
Save ekisu/ac77abb91e58374499651a876aaca062 to your computer and use it in GitHub Desktop.
Test language bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment