我将介绍一下我制作的代码的一些小窍门。那就是:任何特定的方式来剥离特定文本中的多个单词?
url = urlopen("http://sports.yahoo.com/nhl/scoreboard?d=2013-01-19")
content = url.read()
soup = BeautifulSoup(content)
def yahooscores():
for table in soup.find_all('table', class_='player-title'):
for row in table.find_all('tr'):
date = None
for cell in row.find_all('td', class_='yspsctnhdln'):
for text in cell:
date = cell.text
if date is not None:
print ('%s' % (date) + ", 2013:")
我试图去从网站的日期部分剥离话“成绩&时间表”,但我不能以某种方式与.split()和.strip做到这一点( ) 方法。
因此,让我解释一下我想做什么,以上面的网站为例。
到目前为止,这是什么出来约会:
Scores & Schedule: Jan 19, 2013:
我只是想这一点:
Jan 19, 2013:
有没有什么特别的,我需要,以便除去那些3知道话?
是的,这是最好的答案。我注意到日期在“2013年:”的印刷版之间有一个空格,并且将它们结合在一起。我对日期的%%表示歉意。我发布后,我意识到它没有任何目的。 –