次のコードは正常に動作します。特定の日付(つまり、01/04/2017)に新聞を廃棄することですが、daterangeを作成して毎日ループして空になります値は、コードの下に、そして私はおそらく簡単ですが、私は、勉強はまだ、これらの問題が表示されない、'for loop'空の値を返すループ
url = 'http://servicios.lanacion.com.ar/archivo-f01/04/2017-c30'
sauce = uReq(url)
soup = bs.BeautifulSoup(sauce,'html.parser')
date = soup.findAll('div',{'class':'titFecha'})
date = str(date)
fecha = '"titFecha">'
date = date[date.find(fecha)+len(fecha):date.find(fecha)+21]
day = date[:2]
month = date[3:5]
year = date[6:12]
print date
filename = 'La Nacion_%s_%s_%s.csv' % (day, month, year)
f = open(filename,'w')
headers = "Date, Title, Encabezado\n"
f.write(headers)
acumulados = soup.findAll('li',{'class':'acumulados'})
for acum in acumulados:
title = acum.a['href']
# title = title.text
print title
encabezado = acum.p
# encabezado = encabezado.text
print encabezado,'\n'
f.write(str(date) + ',' + str(title).replace(',',' ') + ',' + str(encabezado).replace(',',' ') + '\n')
f.close()
を入れて、ここではループであり、感謝!
date_range = pd.date_range('2017-04-01',periods=2, freq='d')
date_range = date_range.strftime("%d/%m/%y")
for i in date_range:
url = 'http://servicios.lanacion.com.ar/archivo-f%r-c30' % i
sauce = uReq(url)
soup = bs.BeautifulSoup(sauce,'html.parser')
date = soup.findAll('div',{'class':'titFecha'})
date = str(date)
fecha = '"titFecha">'
date = date[date.find(fecha)+len(fecha):date.find(fecha)+21]
day = date[:2]
month = date[3:5]
year = date[6:12]
print date
filename = 'La Nacion_%s_%s_%s.csv' % (day, month, year)
f = open(filename,'w')
headers = "Date, Title, Encabezado\n"
f.write(headers)
acumulados = soup.findAll('li',{'class':'acumulados'})
for acum in acumulados:
title = acum.a['href']
print title
encabezado = acum.p
print encabezado,'\n'
f.write(str(date) + ',' + str(title).replace(',',' ') + ',' + str(encabezado).replace(',',' ') + '\n')
f.close()
何「空の価値を得る」という意味ですか?どこ?出力ファイルには?あなたの 'print'ステートメントはどうですか? –
問題を[MCVE]に絞り込みます。すべての質問でこの指示を繰り返す必要はありません! –