くだすれPython(超初心者用) その23at TECH
くだすれPython(超初心者用) その23 - 暇つぶし2ch65:デフォルトの名無しさん
14/05/31 22:54:07.79 CxiaUoc1
長文ですいません、質問お願いします。
BeautifulSoupで特定のurlのみを抜きたい場合、例えば以下のような

<div id="tieup_list_content">
<div id="tieup_list_content-0" class="test">
<ul>
<li class="clearfix">
<div class="left-col">
<a class="head-text" href="URLリンク(cookpad.com) target="_top">
</div>
<div class="right-col">
<::after>
</li>
</ul>
</div>
<div id="tieup_list_content-1" class="test">
<div id="tieup_list_content-2" class="test">
<div id="tieup_list_content-3" class="test">

構造の場合、
for list in soup.findAll("a",class_="head-text"):
if ( list.has_key('href') ):
print (list["href"])

と書いても抜けません。class='test'としても、最初にfor tieups in soup.find('div',{'id':'tieup_list_content'}):
を書いてみたのですが駄目でした。どう書いたらいいでしょうか?


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch