使用循环读取多个网页

2024-04-24 08:50:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用一个函数(movies\ from\ url)从一个网页上读取总共256部电影。每页包含50部电影。我要读这篇文章的前6页(250部电影5页,6部电影6页)。你知道吗

第一个url:

http://www.imdb.com/search/title?at=0&sort=user_rating&start=1&title_type=feature&year=2005,2014

这是我模糊的想法:

def read_m_by_rating(first_year=2005, last_year=2015, top_number=256):
    current_index=1   # current index is start number  of a webpage 
    final_list = []
    for _ in xrange(6):
    url = http://www.imdb.com/search/title?at=0&sort=user_rating&start=current_index&title_type=feature&year=2005,2014
    if top_number==300:
         lis = movies_from_url(url, top_number - current_index + 1)
    else:
         lis = movies_from_url(url, 50)

    final_list.append(lis)
    current_index=+50
    return final_list

Tags: fromurlnumberindex电影titletopcurrent
1条回答
网友
1楼 · 发布于 2024-04-24 08:50:55

只要在当前索引上使用一个简单的循环就可以了。你知道吗

while current_index<256:
    url = "http://www.imdb.com/search/title?at=0&sort=user_rating&start="\
    +str(current_index)+"&title_type=feature&year=2005,2014"
    ...
    ...
    current_index+=50
return final_list

相关问题 更多 >