Python noob here。我試圖用Python在HTML文件中打印包含子字符串的行。我知道該字符串在文件中,因爲當我按Ctrl + f在html文件中搜索的字符串時,我發現它。但是,當我運行我的代碼時,它不打印所需的結果。有人能解釋我做錯了什麼嗎?尋找HTML文件中的字符串?
import requests
import datetime
from BeautifulSoup import BeautifulSoup
now =datetime.datetime.now()
cmonth = now.month
cday = now.day
cyear = now.year
find = 'boxscores/201'
url = 'http://www.basketball-reference.com/boxscores/index.cgi?lid=header_dateoutput&month={0}&day=17&year={2}'.format(cmonth,cday,cyear)
response = requests.get(url)
html = response.content
print html
for line in html:
if find in line:
print line