Created
March 2, 2018 07:00
-
-
Save kevbo/d0287c2868cd9cf0a9e4bb6aa47b2342 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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