Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bgg_by_id.py
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium import common
from tqdm import tqdm
from urllib import request
import os
import random
import pandas as pd
import getpass
import sys
import time
options = webdriver.FirefoxOptions()
options.headless = True
options.set_preference("dom.webnotifications.enabled", False)
ff = webdriver.Firefox(options=options)
def get_bgg_xml_soup(i):
ff.get(f'https://www.boardgamegeek.com/xmlapi2/thing?id={i}')
return BeautifulSoup(
ff.page_source,
'xml',
)
def get_url_type():
return None
def candidates_to_ff(
start_id: int,
count: int,
):
for i in range(start_id, start_id+count):
time.sleep(2)
soup = get_bgg_xml_soup(i)
try:
if soup.find('items').find('item').get('type') != 'boardgame': # not a boardgame
print(i, soup.find('items').find('item').get('type'))
continue
except AttributeError:
print(i, soup.page_source)
continue
os.popen(f'firefox www.boardgamegeek.com/boardgame/{i}')
candidates_to_ff(
start_id=277250,
count=250,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.