【发布时间】:2021-01-17 11:38:17
【问题描述】:
我正在尝试抓取 https://www.oddsportal.com/soccer/chile/primera-division/curico-unido-o-higgins-CtsLggl6/#over-under;2;6.50;0 中包含的赔率数据
我对“Over Under”部分感兴趣,其中有两个提供商 Pinnacle 和 AsianOdds 的具体高于/低于赔率,可以在“比较”按钮后面找到
在使用开发者工具时,可以看到这些都包含在以下HTML中:
<div class=" deactivateOdd" onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-4.50-0-0','4j5hgx1tkucxe2x0',476,event,0,1)">7.54</div>
我已经让 Selenium 打开页面,切换到 Over/Under 选项卡并展开所有“比较”部分。
url='https://www.oddsportal.com/soccer/chile/primera-division/curico-unido-o-higgins-CtsLggl6/'
browser.get(url)
browser.maximize_window()
time.sleep(2)
#Open match
match=browser.page_source
# with open("matches.html", "w") as file:
# file.write(match)
#Click Over/Under Tab
overunder=browser.find_element_by_css_selector("a[title='Over/Under']").click()
#odds_table=browser.find_element_by_class_name("bt-1").click()
#Enter Odds table
odds_table = browser.find_element_by_class_name('bt-1')
browser.execute_script("arguments[0].click();", odds_table)
browser.maximize_window()
odds_rows = WebDriverWait(browser, 10).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, '.table-header-light')))
for i in odds_rows:
count = i.find_element_by_xpath('./span[@class="odds-cnt"]')
elem = i.find_elements_by_xpath('.//*[contains(text(),"Compare")]')
txt = count.text
if txt != '' and len(elem):
elem = elem[0]
browser.execute_script("arguments[0].scrollIntoView();", elem)
elem.click()
但是在运行时 几率=browser.page_source
使用 open("odds.html", "w") 作为文件: file.write(赔率)
生成的页面源不包含上述包含赔率的 HTML。 我在这里错过了什么?
【问题讨论】: