我將介紹一下我製作的代碼的一些小竅門。那就是:任何特定的方式來剝離特定文本中的多個單詞?
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年:」的印刷版之間有一個空格,並且將它們結合在一起。我對日期的%%表示歉意。我發佈後,我意識到它沒有任何目的。 –