博彩公司的网页抓取赔率

时间:2020-08-05 19:20:27

标签: python web-scraping beautifulsoup selenium-chromedriver

我遇到同样的问题,URL应该为http://op1.win007.com/oddslist/1726223.htm

enter image description here

from selenium import webdriver
from bs4 import BeautifulSoup

url = "http://op1.win007.com/oddslist/1726223.htm"
browser = webdriver.Chrome()
browser.get(url)
soup = BeautifulSoup(browser.page_source, 'html.parser')

containers = soup.findAll("table", {"class": "tcenter"})
print (containers)

在打印容器后,显示所有公司和赔率。

如何显示Bet365赔率并将表格输出到excel如下(仅bet365)

Bet365 3.00 3.40 2.50 32.44 28.63 38.93 97.33 0.96 1.00 0.96

有人可以帮助我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您在页面上看到的数据是从外部源加载的。这是打印Bet 365行的脚本:

import re
import json
import requests


url = 'http://1x2d.win007.com/1726223.js'
js_text = requests.get(url).text

game = re.search(r'game=Array\((".*")\)', js_text).group(1)
data = json.loads('[' + game + ']')

for g in data:
    g = g.split('|')
    if 'Bet 365' in g:
        print(g)
        break

打印:

['281', '87788166', 'Bet 365', '2.75', '3.3', '2.5', '34.09', '28.41', '37.5', '93.75', '2.3', '3.4', '3.4', '42.5', '28.75', '28.75', '97.75', '0.92', '0.99', '1.05', '2019,08-1,02,18,45,00', 'bet 365(英国)', '1', '0']