【问题标题】:Print the results from re.findall on a seperate line in Python3在 Python3 的单独行上打印 re.findall 的结果
【发布时间】:2014-08-15 06:34:32
【问题描述】:

我想在每场比赛的新行上打印 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)

【问题讨论】:

  • 到目前为止你尝试了什么?
  • @m.wasowski 我刚刚添加了我尝试过的内容。对不起

标签: python regex web-scraping


【解决方案1】:

做吧

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

【讨论】:

    【解决方案2】:

    使用for 循环。

    for t in title:
        print(t)
    

    【讨论】:

    • @timgeb 你怎么知道的?
    • @RaydelMiranda urllib.request
    • 哎呀,python 3,whaddidido?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多