Py学习  »  Python

Web刮削循环python问题

smk90 • 5 年前 • 983 次点击  

我是一个python的新手,想知道是否有人能够强调一下我在下面的webscraping脚本中出错的地方。

我正试图递归地遍历匹配列表,为每个匹配提取一个累积值(度量)。

我的问题是,每次返回的值完全相同。

我试着添加注释来解释我的每一个观点,任何帮助都表示感谢。

#use Selenium & Beautiful Soup
from selenium import webdriver
import time
from bs4 import BeautifulSoup 

#define URL/driver
my_url = "https://www.bet365.com/#/IP/"

driver = webdriver.Edge()
driver.get(my_url)

#allow a sleep of 10 seconds
time.sleep(10)

#parse the page
pSource= driver.page_source
soup = BeautifulSoup(pSource, "html.parser")


#containers tag - per match
containers = soup.findAll("div", {"class": "ipn-TeamStack "})
for container in containers:
     #Total Match Shots
     cumul_match_shots = 0    
     match = container.find_all('div')
     for data in soup.findAll('div',{'class':'ml1-SoccerStatsBar '}):  
         for result in data.find_all('span'):
             a = result.text
             if len(a) > 0:
                 cumul_match_shots += int(a)
    #print out values
     print(match)
     print(cumul_match_shots)
#close the webpage
driver.close()           `
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38092
 
983 次点击  
文章 [ 1 ]  |  最新文章 5 年前