簡體   English   中英

使用 SELENIUM/BS4 進行抓取

[英]Scraping using SELENIUM/BS4

我正在嘗試從此頁面https://www.flashscore.pl/druzyna/ajax/8UOvIwnb/tabela抓取數據

如何用“;”分隔結果? 我怎樣才能准確地選擇我需要的數據?

數據是動態的

結果

 ['1.Ajax20153261:548WWWWP']

預期結果(單獨的;並且在本例中缺少幾行值 20 和值 48)

Ajax;15;3;2;61:5;W;W;W;W;P'

下面的代碼

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from bs4 import BeautifulSoup as BS
import requests
from time import sleep
import re
driver = webdriver.Chrome()
driver.get("https://www.flashscore.pl/druzyna/ajax/8UOvIwnb/tabela/")
sleep(10)
page = driver.page_source
soup = BS(page,'html.parser')
content3 = soup.find('div',{'class':'ui-table__body'})
content_list3 = content3.find_all('div',{'class':'tableCellFormIcon 
tableCellFormIcon--TBD'})
res = []
for i in content3:
   line = i.text.split()[0]
   if re.search('Ajax', line):
       line = line.replace("?", "")
       res.append(line)

print(res)

這能解決你的問題嗎?

content3 = soup.find('div',{'class':'ui-table__body'})
content_list3 = content3.find_all('div',{'class':'tableCellFormIcon tableCellFormIcon--TBD'})

content_list3 = content3.find_all('div',{'class':'tableCellFormIcon', 'title': re.compile('Ajax*')})
res = []
for i in content_list3:    
    line = i.text
    line = line.replace("?", "")
    res.append(line)

res = ";".join(res)
print(res)

我沒有將所選內容中的所有文本字段合並,然后搜索 Ajax,而是只選擇了標題中包含“Ajax”的那些 div,並一一獲取它們的文本。 然后,您可以使用偏好分隔符加入它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM