[英]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.