Created
December 21, 2016 04:01
-
-
Save Kyu/56372afe033c2f29195507c5b21cf8d4 to your computer and use it in GitHub Desktop.
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 | |
s = requests.session() | |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'} | |
url = 'http://blocgame.com' | |
data = {'username': 'USERNAME', 'password': 'PASSWORD', 'login': ''} | |
s.headers['User-Agent'] = headers['User-Agent'] | |
login = s.post(url+'/login.php', data=data, headers=headers) | |
#main = s.get(url+'/main.php') | |
def get_alliances(pages=1): | |
if pages < 1: | |
return | |
alliances = [] | |
soups = [] | |
for i in range(1, pages+1): | |
soups.append(BeautifulSoup(s.get(url + '/alliancerankings.php?page={}'.format(i)).text, 'html.parser')) | |
for soup in soups: | |
for link in soup.find_all('a', href=True): | |
if link['href'].startswith('alliancestats') and link not in alliances: | |
alliances.append(link['href']) | |
return alliances | |
# Tests | |
# print(get_alliances(pages=2)) | |
# print(get_alliances(pages=-1) is None) | |
def get_alliance(num=None, name=None): | |
if not num and not name or num and name: | |
return "Invalid args" | |
raise NotImplemented("Soon tee em") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment