71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
import requests
|
|
from bs4 import BeautifulSoup
|
|
from ratelimit import limits, sleep_and_retry
|
|
|
|
# Set up rate limiter, one request per second
|
|
CALLS = 1
|
|
RATE_LIMIT = 1
|
|
|
|
@sleep_and_retry
|
|
@limits(calls=CALLS, period=RATE_LIMIT)
|
|
def get_group_details(group_url_name):
|
|
# Regular group page URL
|
|
group_url = f"https://steamcommunity.com/groups/{group_url_name}"
|
|
|
|
try:
|
|
group_page_response = requests.get(group_url)
|
|
group_page_response.raise_for_status()
|
|
except requests.HTTPError as http_err:
|
|
print(f"HTTP error occurred: {http_err}")
|
|
return
|
|
except Exception as err:
|
|
print(f"Other error occurred: {err}")
|
|
return
|
|
|
|
group_page_soup = BeautifulSoup(group_page_response.text, "lxml")
|
|
|
|
# Group Tag
|
|
tag_span = group_page_soup.find("span", {"class": "grouppage_header_abbrev"})
|
|
tag = tag_span.text.strip() if tag_span else "No tag"
|
|
|
|
# Group details XML page URL
|
|
group_details_url = (
|
|
f"https://steamcommunity.com/groups/{group_url_name}/memberslistxml/?xml=1"
|
|
)
|
|
|
|
try:
|
|
group_details_response = requests.get(group_details_url)
|
|
group_details_response.raise_for_status()
|
|
except requests.HTTPError as http_err:
|
|
print(f"HTTP error occurred: {http_err}")
|
|
return
|
|
except Exception as err:
|
|
print(f"Other error occurred: {err}")
|
|
return
|
|
|
|
try:
|
|
group_details_soup = BeautifulSoup(group_details_response.content, "lxml-xml")
|
|
|
|
# Group Name
|
|
group_name = group_details_soup.find("groupName").text
|
|
|
|
# Group ID64
|
|
group_id64 = group_details_soup.find("groupID64").text
|
|
|
|
# Member List
|
|
members = [member.text for member in group_details_soup.find_all("steamID64")]
|
|
|
|
return {
|
|
"group_id64": group_id64,
|
|
"group_name": group_name,
|
|
"group_url": group_url,
|
|
"tag": tag,
|
|
"members": members,
|
|
}
|
|
|
|
except Exception as err:
|
|
print(f"Error occurred during parsing of group details XML page: {err}")
|
|
|
|
if __name__ == "__main__":
|
|
# Replace 'ilovebloop' with the desired group URL name
|
|
print(get_group_details("CheeseFraud"))
|