Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
Forked from kevbo/nbastats.py
Created June 28, 2018 03:38
Show Gist options
  • Save liquidgenius/00eb4fc9624e30622ad4291b4b5c5c15 to your computer and use it in GitHub Desktop.
Save liquidgenius/00eb4fc9624e30622ad4291b4b5c5c15 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from pyquery import PyQuery as pq
# Set options
options = webdriver.ChromeOptions()
options.add_argument('headless')
try:
driver = webdriver.Chrome(chrome_options=options)
except:
pass
# Open page and wait for the elements we want to pop in
driver.get('https://stats.nba.com/game/0021700723/')
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "game-summary__date"))
)
# Scrape with just Selenium
high_score = driver.find_element_by_css_selector('.score.final.red')
print(high_score.text)
# Scrape with PyQuery
q = pq(driver.find_element_by_tag_name('html').get_attribute('innerHTML'))
print(q('td.score.final.red').text())
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment