如何在循环的第一个实例中跳过前三个元素

时间:2020-02-19 11:58:46

标签: python-3.x web-scraping

如何使用python

实现
all(rownames(phenotype) == colnames(countData))

我如何打印不包括第一个季节的前三个日期,但打印每个其他季节的所有其他日期?

例如,第1季有6个日期,第2季有5个日期: 我希望得到这样的输出,其中排除了第1季的前3个日期:

for season in seasons:
    print('Season:',season)
    season_response = requests.get(season, headers=headers, cookies=cookies)
    season_content = season_response.content
    season_doc = html.fromstring(season_content)
    dates = [base + date for date in season_doc.xpath('//*[@id="bloccontenu"]//div[@class="select-container select-game"]/select/option/@value')]
    for date in dates:
        print(date)
        # print dates
        # exclude the first three dates of only the first instance of loop

1 个答案:

答案 0 :(得分:1)

for season in seasons:
    print('Season:',season)
    season_response = requests.get(season, headers=headers, cookies=cookies)
    season_content = season_response.content
    season_doc = html.fromstring(season_content)
    dates = [base + date for date in season_doc.xpath('//*[@id="bloccontenu"]//div[@class="select-container select-game"]/select/option/@value')]

    if season == seasons[0]:
        dates = dates[3:]

    for date in dates:
        print(date)

当季节等于第1季时,丢弃前3个日期吗?