我尝试了两种方法来查找投注奇数,但没有结果。我一无所获。
这是代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import pandas as pd
PATH = "C:Program Files (x86)chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.optibet.lv/sport/wcg/CS:GO-5541")
odds = driver.find_elements_by_class('event-block-row__odd event-block-row__odd_clickable event-block-row__odd_without-middle-odd')
if odds is not None:
print('found odds element')
print(odds)
这没用。它只是打印"找到的赔率元素"。然后我尝试将类名更改为odds = driver.find_elements_by_class('odd__value')
,但没有成功。之后,我尝试使用BeautifulSoup:
from selenium import webdriver
from bs4 import BeautifulSoup
url = "https://www.optibet.lv/sport/wcg/CS:GO-5541"
driver = webdriver.Chrome()
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'html.parser')
containers = soup.find_all("div", class_="event-block-row__odd event-block-row__odd_clickable event-block-row__odd_without-middle-odd")
print (len(containers))
这将返回"0"。我没有主意,经验也不多。有什么帮助吗?
在获取类之前切换到iframe。然后循环列表。
driver.get("https://www.optibet.lv/sport/wcg/CS:GO-5541")
driver.implicitly_wait(10)
driver.switch_to.frame(driver.find_element_by_css_selector("#iFrameResizer0"))
odds = driver.find_elements_by_class_name('odd__value')
if odds is not None:
print('found odds element')
for odd in odds:
print(odd.text)
许多站点都有刮板保护,其次,您的站点非常重。你可以试试这个,但BeautifulSoup有局限性:
from bs4 import BeautifulSoup
import urllib.request
import bs4 as bs
url_1 = 'https://www.optibet.lv/sport/wcg/CS:GO-5541'
sauce_1 = urllib.request.urlopen(url_1).read()
soup_1 = bs.BeautifulSoup(sauce_1, 'lxml')
for table in soup_1.find('div', class_='event-block-row__odd event-block-row__odd_clickable event-block-row__odd_without-middle-odd'):
print(table.text)