Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在循环的第一个实例中跳过前三个元素_Python 3.x_Web Scraping - Fatal编程技术网

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

Python 3.x 如何在循环的第一个实例中跳过前三个元素,python-3.x,web-scraping,Python 3.x,Web Scraping,如何使用python实现这一点 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 =

如何使用python实现这一点

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季有6个日期,第2季有5个日期: 我期望这样的输出,其中第1季的前3个日期被排除在外:

Season: season 1  
date4
date5
date6
Season: season 2
date1
date2
date3
date4
date5

当季节等于季节1时,放弃前3个日期?

你能在
季节中发布前两个元素的(简化版,如有必要)版本吗?
?谢谢@Juke。你的回答实际上让我知道该怎么办。如果季节==季节[0]:日期=日期[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')]

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

    for date in dates:
        print(date)