-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
47 lines (33 loc) · 1.71 KB
/
scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
keywords = input("input keywords eg: nitro+kpop+minecraft ")
sort = input("sort by bumped recently, or member count? [1/2] ")
if sort == "1":
disboardUrl = f"https://disboard.org/search?keyword={keywords}&sort=bumped_at"
elif sort == "2":
disboardUrl = f"https://disboard.org/search?keyword={keywords}&sort=-member_count"
i = 1
browser = webdriver.Chrome(chrome_options=options)
while True:
request = requests.get(f"{disboardUrl}&page={i}", headers={'User-Agent': 'Mozilla/5.0'})
soup = BeautifulSoup(request.text, 'html.parser')
server_card = soup.findAll('div', class_="column is-one-third-desktop is-half-tablet")
disboardServerIDs = []
for card in server_card:
disboardServerID = card.find('a', class_="button button-join is-discord").get('data-id')
disboardServerIDs.append(disboardServerID)
options = Options()
options.add_argument('--headless')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
for Id in disboardServerIDs:
browser.get(f"https://disboard.org/server/join/{Id}")
url = WebDriverWait(browser, 10).until(EC.url_contains('https://discord.com/invite/'))
print(browser.current_url)
with open("invites.txt", "a") as file:
file.write(f'{browser.current_url}\n')
i = i + 1
browser.close()