【发布时间】:2021-11-18 16:36:00
【问题描述】:
我正在尝试创建团队及其赔率的显示。
我想在数据框中执行此操作。我已经刮掉了他们的胜算。
我想将球队和赔率放在不同的列中。
我想要单独的游戏在不同的行上。
我已设法以以下形式返回列表:
['Buffalo Bills 1.30 Washington Football Team 3.50',
'Kansas City Chiefs 1.35 Los Angeles Chargers 3.25',]
我需要返回列表或对其进行切片,使其显示如下:
[['San Francisco 49ers, 1.62, Green Bay Packers, 2.30'],
['Dallas Cowboys, 1.57, Philadelphia Eagles, 2.40],]
目前使用的代码如下:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',options=chrome_options)
url = str("https://www.ladbrokes.com.au/sports/american-football/nfl")
wd.get(url)
time.sleep(5)
html = wd.page_source
html
SCROLL_PAUSE_TIME = 1
# Get scroll height
last_height = wd.execute_script("return document.body.scrollHeight")
while True:
#Scroll down to bottom
wd.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
games = wd.find_elements_by_class_name("sports-market-primary__prices-inner")
# Calculate new scroll height and compare with last scroll height
new_height = wd.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
result=[]
for i in games:
var = i.text
var = str(var).replace('\n',' ')#.split()
result.append(var)
'''
【问题讨论】:
标签: python web-scraping split slice