正在从 div 抓取数据

Crawling data from a div

早上好,我想从 div 抓取数据时没有什么问题。例如我在网站上有这样的结构:

<div class="score-result">
Player1Name
Player1Surname
<div>score</div>
</div>

我想知道球员的姓名和分数。我已经这样写了,但是它没有打印任何东西。

def trade_spider(max_hall,max_period):
    hall=2
    period=1
    while hall <= max_hall:
        url ='https://tabletennis.setkacup.com/en/schedule?date=2021-08-27&hall=' +str(hall)+'&'+'period='+str(period)
        source_code = requests.get(url)
        plain_text=source_code.text
        soup=BeautifulSoup(plain_text, "html.parser")
        for link in soup.findAll('table', {'class': 'score-result'}):
            score = link.get('score-result')
            print(score)
            hall=+1
            period=+1

请检查您这边的代码。

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


service = webdriver.chrome.service.Service(os.path.abspath('chromedriver'))
service.start()
option = webdriver.ChromeOptions()


driver = webdriver.Chrome(os.path.abspath('chromedriver'), options=option)

hall = 2
period = 1
while hall <= 5:
    url = 'https://tabletennis.setkacup.com/en/schedule?date=2021-08-27&hall=' + \
        str(hall)+'&'+'period='+str(period)
    driver.get(url)
    time.sleep(5)
    divs = driver.find_elements_by_css_selector("div.score-result")
    for div in divs:
        # you can add this code
        try :
            fund = div.find_element_by_tag_name("div").text
            print(fund)
        catch :
            pass

        print(div.text)

    hall = hall + 1

希望对你有所帮助