Created
July 9, 2018 09:25
-
-
Save dj-shin/3a42a24d58b93428de991df57b96e62a 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 as bs | |
def get_userlist(): | |
url = 'http://sillim.interdaim.com/compareRecordTop.php' | |
resp = requests.get(url, cookies={'PHPSESSID': 'f1fe2cd9aec08943950d8e5926e0b158'}) # PHPSESSID is required | |
data = resp.content.decode('euc-kr', 'ignore') | |
soup = bs(data, 'html.parser') | |
form = soup.find('form') | |
users = {option.get_text(): int(option['value']) for option in form.find_all('option')} | |
return users | |
def get_record(nick1, nick2): | |
url = 'http://sillim.interdaim.com/compareRecordBottom.php' | |
resp = requests.post(url, cookies={'PHPSESSID': 'f1fe2cd9aec08943950d8e5926e0b158'}, data={'nick1': nick1, 'nick2': nick2}) | |
data = resp.content.decode('euc-kr', 'ignore') | |
soup = bs(data, 'html.parser') | |
parsed = [[[td.get_text().strip() for td in tr.find_all('td')] for tr in table.find_all('tr')] for table in soup.find_all('table')[1:]] | |
return parsed | |
def main(): | |
users = get_userlist() | |
nick1 = users['토마스'] | |
nick2 = users['제리'] | |
record = get_record(nick1, nick2) | |
print(record) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment