Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import requests
- import random
- from datetime import datetime
- random.seed(datetime.now().timestamp())
- target_page = "https://www.ptt.cc/bbs/C_Chat/M.1716883408.A.953.html"
- response = requests.get(url = target_page, cookies = {"over18": "1"})
- soup = BeautifulSoup(response.text, "html.parser")
- pool = {}
- for i in soup.select(".push") :
- push_id = i.select_one('.push-userid').get_text()
- push_type = i.select_one('.push-tag').get_text()
- push_content = i.select_one('.push-content').get_text()
- #print(f"{push_id:<12} {push_type}{push_content}")
- if not push_id in pool.keys() and push_type != "噓 " and ": cat0808: 甜點貓的胸是墊出來的" in push_content :
- pool[push_id] = {"type": push_type, "content": push_content}
- print(f"Total: {len(pool)}")
- subgroup_size = 8
- max_winner = 10
- winner = []
- pool_group = ([list(pool.keys())[i : i + subgroup_size] for i in range(0, len(pool.items()), subgroup_size)])
- for i in pool_group :
- if len(i) < subgroup_size or max_winner <= len(winner) :
- break
- x = random.randrange(subgroup_size)
- winner.append(i[x])
- for j in range(subgroup_size) :
- if j == x :
- print(f"\033[91m{i[j]:<12}\033[0m", end = ' ')
- else :
- print(f"{i[j]:<12}", end = ' ')
- print("\n")
- print(winner)
Advertisement
Add Comment
Please, Sign In to add comment