BeatifulSoupを使用して、あるサイトのHTMLから特定の要素のouterHTMLを取得しました。
さらに取得したHTMLの下記の要素の値を取得したいのですが
どのように取得すればいいのでしょうか?
table#chart > tbody > tr > tdの最後の要素(e.g. <td>-4132</td>)
###該当のソースコード
Python
1#!/usr/local/python3 2from bs4 import BeautifulSoup 3import requests 4 5local = "http://localhost:8000/" 6url = F"{local}hogehoge.html" 7r = requests.get(url) 8soup = BeautifulSoup(r.text, 'lxml') 9Data = soup.select('table#chart') 10 11#--------------------取得したHTML--------------------------- 12<table class="data hide" id="chart"> 13 <thead> 14 <tr> 15 <td></td> 16 <th scope="col">564</th> 17 <th scope="col">1764</th> 18 <th scope="col">4165</th> 19 <th scope="col">5365</th> 20 <th scope="col">7285</th> 21 <th scope="col">9145</th> 22 <th scope="col">11005</th> 23 <th scope="col">12926</th> 24 <th scope="col">14727</th> 25 <th scope="col">16586</th> 26 <th scope="col">18387</th> 27 <th scope="col">20187</th> 28 <th scope="col">21988</th> 29 <th scope="col">23848</th> 30 <th scope="col">25648</th> 31 <th scope="col">26908</th> 32 <th scope="col">29369</th> 33 <th scope="col">30569</th> 34 <th scope="col">32489</th> 35 <th scope="col">34289</th> 36 <th scope="col">36149</th> 37 <th scope="col">38010</th> 38 <th scope="col">39870</th> 39 <th scope="col">41671</th> 40 <th scope="col">43651</th> 41 <th scope="col">44911</th> 42 </tr> 43 </thead> 44 <tbody> 45 <tr> 46 <th scope="row"></th> 47 <td>-34</td> 48 <td>-470</td> 49 <td>-788</td> 50 <td>-614</td> 51 <td>-801</td> 52 <td>-1173</td> 53 <td>-1547</td> 54 <td>-1584</td> 55 <td>-1584</td> 56 <td>-1828</td> 57 <td>-2381</td> 58 <td>-2538</td> 59 <td>-2538</td> 60 <td>-2538</td> 61 <td>-2882</td> 62 <td>-2882</td> 63 <td>-2882</td> 64 <td>-2923</td> 65 <td>-3110</td> 66 <td>-3385</td> 67 <td>-3364</td> 68 <td>-3743</td> 69 <td>-4044</td> 70 <td>-3911</td> 71 <td>-4132</td> 72 <td>-4132</td> 73 </tr> 74 </tbody> 75 <tbody> 76 <tr> 77 <th scope="row"></th> 78 <td></td> 79 </tr> 80 </tbody> 81</table> 82#--------------------取得したHTML---------------------------
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。