在Python3中的单独行上打印re.findall的结果

时间:2014-06-24 20:55:04

标签: python regex web-scraping

我想在每个匹配的新行上打印findall结果

Python代码

import urllib.request
import re

htmlfile = urllib.request.urlopen("http://basketball.realgm.com/")

htmltext = htmlfile.read().decode('iso-8859-1')
title = re.findall('">(.+?)</a></h3>', htmltext)

print (title)

结果

['LeBron James Exercises Early Termination Option With Heat', 'LeBron James Exercises Early Termination Option With Heat', 'Heat, Hawks Could Join Pursuit Of Carmelo Anthony', 'Tyler Dorsey Decommits From Arizona', 'Antoine Mason Transfers To Auburn', 'Dario Saric Signs Three-Year Deal With Anadolu Efes', 'Batum To Participate In FIBA World Cup For France', 'Moustapha Diagne Commits To Syracuse']

想要这样的结果:

LeBron James Exercises Early Termination Option With Heat
Heat, Hawks Could Join Pursuit Of Carmelo Anthony
Tyler Dorsey Decommits From Arizona

尝试:

print (title \n)

2 个答案:

答案 0 :(得分:3)

只做

print("\n".join(title))

答案 1 :(得分:2)

使用for循环。

for t in title:
    print(t)