2017-08-11 6 views
0

でテーブルの列を解析私は、このパターンコードを持つテーブルを解析:BeautifulSoup

soup = BeautifulSoup(open("out.html"), 'html.parser') 
tab = soup.findAll('table')[3] 
rows = tab.find_all('tr') 

for sing_row in rows: 
    col = sing_row.find_all('td')[1] 
    print col 

印刷の結果は次のとおりです。

<td class="col-md-3">5.67.43.158<br/><span style="font-size: 0.9em; color: #eee;"></span></td> 
<td class="col-md-3">32.54.44.155<br/><span style="font-size: 0.9em; color: #eee;">ns2.asdf.it</span></td> 
<td class="col-md-3">53.64.21.154<br/><span style="font-size: 0.9em; color: #eee;">server1.adb.it</span></td> 
<td class="col-md-3">23.62.53.22<br/><span style="font-size: 0.9em; color: #eee;">server1.xcvf.it</span></td> 

私の目標は、テーブルからのみIPアドレスを取得することです列内のドメインのない列。どうすればいいですか?

+0

'sing_row.find_all( 'TD')試してみてください[1] –

+0

マーカスを.contents'、もし答えがあなたの望むものであれば、それは「受け入れられた」とマークするべきです。 –

+0

参考:https://stackoverflow.com/help/someone-answers –

答えて

0

あなたはtag.contentsを使用することができます。

ます。また tag.find(text=True)を使用することができます
for sing_row in rows: 
    col = sing_row.find_all('td')[1] 
    print col.contents 

for sing_row in rows: 
    col = sing_row.find_all('td')[1] 
    print col.find(text=True) 
+0

ありがとうございます。 – Marcus

+0

@Marcus投稿したリンクが見えましたか?あなたはこのように感謝することができますhttps://stackoverflow.com/help/someone-answers :) –