Created
October 4, 2022 18:11
-
-
Save jarrodnorwell/305084f6d6ec781de19cb863a165ac91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from bs4 import BeautifulSoup | |
import json, os, requests | |
def device() -> dict: | |
response = requests.get('https://www.myfakeinfo.com/mobile/get-android-device-information.php') | |
soup = BeautifulSoup(response.text, 'html.parser') | |
container = soup.find('div', class_='container') | |
rows = container.find_all('div', class_='row') | |
for row in rows: | |
if row.find('div', class_='col-md-9'): | |
table = row.find('div', class_='row') | |
row_contents = table.find_all('div', class_='row content') | |
double_columns = row_contents[:11] | |
single_columns = row_contents[12:] | |
keys = [] | |
values = [] | |
for double_column in double_columns: | |
double_columns_rows = double_column.find_all('div') | |
keys += [key.text.lower() for key in double_columns_rows[0::2]] | |
values += [value.text for value in double_columns_rows[1::2]] | |
for single_column in single_columns: | |
single_columns_rows = single_column.find_all('div') | |
keys += [key.text.lower() for key in single_columns_rows[0::2]] | |
values += [value.text for value in single_columns_rows[1::2]] | |
device = {} | |
for key in keys: | |
for value in values: | |
device[key] = value | |
values.remove(value) | |
break | |
return device | |
if __name__ == '__main__': | |
with open(os.getcwd() + '/device.json', 'w', encoding='utf-8') as file: | |
json.dump(device(), file, ensure_ascii=True, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment