我正在抓取一个带有无限卷轴的网站,由于我的无限卷轴使用selenium可以很好地工作,当我添加条件时,它只记录数据直到第一个卷轴 可能的问题是什么
(完全相同的滚动,不带条件)
我的代码:
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(randint(1,10))
for a in page.find_all('a', href=True): <--Condition
print("Found the URL:", a['href']) <----Condition
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
相关问题 更多 >
编程相关推荐