我的BeautifulSoup搜寻器会遍历URL列表,并根据需要捕获我的条件之一(“ month_year”)。但是第二个循环中的每个“ li”标记仅提取页面上第一个实例的详细信息。
给定URL的'month_year'不变,这很好。但是“广播”应该为每个“ li”标签返回不同的详细信息。
对新手有什么建议吗?
contents = []
with open('monthly_list.csv','r') as csvf:
urls = csv.reader(csvf)
for url in urls:
page = urlopen(url[0]).read()
tunes = BeautifulSoup(page, 'html.parser')
playlist = tunes.find('ul', class_='content-container row')
daily_URLs_data = open('daily_URLs_2007-2018.csv', 'a')
for li in playlist.find_all('div', class_='description'):
month_year = tunes.find('div', class_='resultsHeader').text
broadcast = playlist.h3.a
print (month_year)
print (broadcast)
csv_writer.writerow([month_year, broadcast])