from bs4 import BeautifulSoup as Soup
import requests
from bs4 import Tag
import json
response = requests.get('https://www.sslproxies.org')
soup = Soup(response.content, 'html.parser')
headers = dict(
enumerate(
map(
lambda x: x.get_text(strip=True).lower().replace(' ', '_'),
soup.select('div.fpl-list thead th')
)
)
)
def line_to_dict(val: Tag):
for i in range(len(td := val.find_all('td'))):
yield headers.get(i), td[i].get_text(strip=True)
with open('result.json', 'w', encoding='utf-8') as f:
json.dump(
list(
dict(line_to_dict(item))
for item in soup.select('div.fpl-list tbody tr')
),
f,
ensure_ascii=False,
indent=2
)
[
{
"ip_address": "198.44.162.8",
"port": "45787",
"code": "JP",
"country": "Japan",
"anonymity": "elite proxy",
"google": "no",
"https": "yes",
"last_checked": "1 min ago"
},
{
"ip_address": "200.105.215.22",
"port": "33630",
"code": "BO",
"country": "Bolivia",
"anonymity": "elite proxy",
"google": "no",
"https": "yes",
"last_checked": "1 min ago"
},
...
{
"ip_address": "213.241.205.2",
"port": "3129",
"code": "RU",
"country": "Russian Federation",
"anonymity": "anonymous",
"google": "no",
"https": "yes",
"last_checked": "1 min ago"
}
]