python – 美丽的汤findall多个类使用一个查询
发布时间:2020-12-20 13:49:29 所属栏目:Python 来源:网络整理
导读:我在很多网站和这里彻底搜索了解决方案,但没有一个有效! 我正在尝试刮掉flashscores.com,我想解析一个 td使用类名称cell_ab team-home或cell_ab team-home bold 我尝试过使用re soup.find_all('td',{ 'class'= re.compile(r"^(cell_ab team-home |cell_ab t
我在很多网站和这里彻底搜索了解决方案,但没有一个有效!
我正在尝试刮掉flashscores.com,我想解析一个< td>使用类名称cell_ab team-home或cell_ab team-home bold 我尝试过使用re soup.find_all('td',{ 'class'= re.compile(r"^(cell_ab team-home |cell_ab team-home bold )$")) 和 soup.find_all('td',{ 'class' : ['cell_ab team-home ','cell_ab team-home bold ']) 它们都不起作用. 有人请求代码,所以在这里 from tkinter import * from selenium import webdriver import threading from bs4 import BeautifulSoup browser = webdriver.Firefox() browser.get('http://www.flashscore.com/') HTML = browser.page_source soap = BeautifulSoup(HTML) for item in soap.find_all('td',class_ = ['cell_ab team-home ','cell_ab team-home bold ']): Listbox.insert(END,item.text) 解决方法bs4 documentation说下面关于使用class_进行匹配:
根据文档,您必须使用.select方法在此处使用CSS选择器.因此,这样的事情应该做的伎俩: soup.select('td.cell_ab.team-home') 这将选择设置了cell_ab和team-home类的所有< td>,包括具有附加类的< td>,例如粗体. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |