我使用 beautifulsoup 庫,我想從代碼中的特定部分抓取元素,這是我的代碼:
#Partie scrapping
soup = BeautifulSoup(page.content, 'html.parser')
print(soup.title) #Permet d'afficher toute la page
print("Récupération de vos notes en cours...")
#Récupération des titres
liste_titres = soup.find_all("span", class_="ui-column-title")
div_notes = soup.find_all("tr", role="row")
for i in liste_titres:
if i == None:
print("La case est vide")
else:
print(i.string, end=" ")
#Recuperation des matieres
notes = soup.find_all("tr", class_="ui-widget-content ui-datatable-even odd-row")
for i in notes:
if i == None:
print("La case est vide")
else:
print(i)
這是我要刮的部分:
<tr data-ri="0" class="ui-widget-content ui-datatable-even odd-row" role="row"><td role="gridcell" style="width:250px" class="mg_inherit_bg"><span class="mg_inherit_color" style="font-weight: bold; font-size: 11px">Algorithmique et structure de données</span></td><td role="gridcell" style="width:100px;"><span style="font-weight: bold; font-size: 11px; color: rgb(93, 93, 93); --darkreader-inline-color:#ada69c;" data-darkreader-inline-color="">M. GABER</span></td><td role="gridcell" style="width:37px;text-align: center">2.00</td><td role="gridcell" style="width:37px;text-align: center">2.00</td><td role="gridcell" style="width:45px;text-align: center">16,5</td><td role="gridcell" style="width:45px;text-align: center"></td><td role="gridcell" style="width:45px;text-align: center"></td><td role="gridcell" style="width:55px;text-align: center"></td></tr>
uj5u.com熱心網友回復:
解決方案只是:
notes = soup.find_all("tr", class_="ui-widget-content ui-datatable-even odd-row")
for i in notes:
if i == None:
print("La case est vide")
else:
print(i.td.string)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/377792.html
上一篇:未知字符“?3ù?ù??·”被抓取而不是編碼utf-8
下一篇:scrapy停止抓取已解決的元素
