用Print能得到所有列表,但是return只返回了第一页,这是为什么呢?

用python爬虫,如果我用print能够返回所有个人详情页,但是如果我使用return,却只能返回第一页的内容,这是为什么呢?我的代码如下:

def get_url():
    links=[]
    personal_links=[]
    page_number=1
    while page_number <=192:
        link=url+'/s?p='+str(page_number)
        links.append(link)
        page_number=page_number+1
        #获取个人详情页
        for link in links:
            r=requests.get(link,headers=headers)
            soup = BeautifulSoup(r.text, 'lxml')
            for data in soup.find('div', {'class': 'result-list'}).findAll('a'):
                if 'href' in data.attrs:
                    if not data.attrs['href'] in personal_links:
                        personal_url=url+data.attrs['href']
                        personal_links.append(personal_url)
        return personal_links
查看回复

相关问答