37,718
社区成员
发帖
与我相关
我的任务
分享
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
tds = soup.find_all('td',class_ = 'td-title faceblue')
for td in tds:
zzr = td.find_all('a')
for a in zzr:
print(a["href"])
find_all时增加个 class_ 参数[/quote]
谢谢from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
tds = soup.find_all('td',class_ = 'td-title faceblue')
for td in tds:
zzr = td.find_all('a')
for a in zzr:
print(a["href"])
find_all时增加个 class_ 参数# -*- coding:utf-8 -*-
html="""
"""
from bs4 import BeautifulSoup
soup=BeautifulSoup(html,'lxml')
zzr=soup.find_all('td',class_="td-title faceblue")
for item in zzr:
list_tmp=item.find_all('a')
for a in list_tmp:
print a.get('href')
# -*- coding:utf-8 -*-
html="""
"""
from bs4 import BeautifulSoup
soup=BeautifulSoup(html,'lxml')
zzr=soup.find_all('a')
for item in zzr:
print item.get("href")
# -*- coding:utf-8 -*-
html="""
<tr class="bg">
<td class="td-title faceblue">
<span class="face" title="普通帖">
</span>
<a href="/post-basketball-200125-1.shtml" target="_blank">
当教练的最高境界——让对手任谁都能打出神仙球!
</a>
</td>
<td><a href="http://www.tianya.cn/75944044" target="_blank" class="author">司马取印</a></td>
<td>4420</td>
<td>163</td>
<td title="2017-04-25 23:44">04-25 23:44</td>
</tr>
<tr>
<td class="td-title faceblue">
<span class="face" title="普通帖">
</span>
<a href="/post-basketball-200496-1.shtml" target="_blank">
10年的黑色乔丹6代!!!(转载)<span class="art-ico art-ico-3" title="内有2张图片"></span>
</a>
</td>
<td><a href="http://www.tianya.cn/126744501" target="_blank" class="author">13141373133</a></td>
<td>102</td>
<td>9</td>
<td title="2017-04-25 17:44">04-25 17:44</td>
</tr>
"""
"""
from bs4 import BeautifulSoup
soup=BeautifulSoup(html,'lxml')
zzr=soup.find_all('a')
print zzr
"""
import re
patt=re.compile(r'<a.*?href="(.*?)"',re.S)
zzr=patt.findall(html)
print zzr