Python 硒罐';在Heroku中部署时找不到div

Python 硒罐';在Heroku中部署时找不到div,python,selenium,heroku,Python,Selenium,Heroku,我试图从这个链接中获取两个表: 当我的应用程序没有部署到Heroku时,我可以像这样抓取它们 import requests import os from bs4 import BeautifulSoup from selenium import webdriver url = 'https://www.nba.com/standings?GroupBy=conf&Season=2019-20&Section=overall' driver = webdriver.Chrome

我试图从这个链接中获取两个表:

当我的应用程序没有部署到Heroku时,我可以像这样抓取它们

import requests
import os
from bs4 import BeautifulSoup
from selenium import webdriver

url = 'https://www.nba.com/standings?GroupBy=conf&Season=2019-20&Section=overall'
driver = webdriver.Chrome()
driver.get(url)

soup = BeautifulSoup(driver.page_source, 'html.parser')
tables = soup.select('div.StandingsGridRender_standingsContainer__2EwPy')
但当我将我的应用程序部署到Heroku时,我必须指定chromedriver,这就是我的代码:

url = 'https://www.nba.com/standings?GroupBy=conf&Season=2019-20&Section=overall'
CHROMEDRIVER_PATH = "/app/.chromedriver/bin/chromedriver"

chrome_bin = os.environ.get('GOOGLE_CHROME_BIN', "chromedriver")
options = webdriver.ChromeOptions()
options.binary_location = chrome_bin
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument('headless')
options.add_argument('window-size=1200x600')
options.add_argument('--disable-dev-shm-usage') 
options.add_argument("--disable-popup-blocking")
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=options)
driver.get(url)

soup = BeautifulSoup(driver.page_source, 'html.parser')
tables = soup.select('div.StandingsGridRender_standingsContainer__2EwPy')
每当我在Heroku上运行这段代码时,我都会收到一个索引器,说列表索引超出范围(我稍后在代码中从表[0]和表[1]中提取表)


有没有办法让我弄明白为什么桌子没有被抢走?是否存在阻止驱动程序访问表的弹出窗口?我试图指定--禁用弹出窗口阻止,但没有成功。谢谢

通过查看代码无法判断发生了什么。最好的办法是检查页面源代码并从那里开始工作。作为黑暗中的刺刀。。。也许你的窗口太小了,以至于改变了页面的格式。也许有什么东西阻止了来自heroku的请求(例如cloudflare或类似的解决方案)——如果不看到浏览器看到的内容,很难说。