Python为每个页面显示相同的结果。靓汤

2024-10-01 09:30:16 发布

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

我对Python非常陌生,我正在尝试从googlescholar那里获取一些东西作为一个项目。出现问题的代码如下所示:

    yearList = []
def getYear():
    for div in soup.find_all("div", class_='gs_a'):
        yearRegex = re.compile(r".*(\d\d\d\d).*")
        yo = yearRegex.findall(div.text)
        yearList.append(yo)
    print(yearList)



page = 0
i = 0 
while i < numPages:

    link = 'https://scholar.google.de/scholar?start=' + str(page) + '&q=' + search + '&hl=de&as_sdt=0,5'
    res = requests.get(link)
    soup = bs4.BeautifulSoup(res.text, 'html.parser')
    getYear()    #this is the function that extracts the data
    page += 20      #to get to the next page of the results
    i += 1`

页面变量和链接实际上每次更改20。但是,由于某种原因,程序只是将搜索结果的第一页刮下来,就好像link变量从未更改过一样。我错过了什么?你知道吗


Tags: thetotextdivgetpagelinkde