Я не могу получить Linkedin для разбивки на страницы, когда я пытаюсь сделать следующее:
URL-адрес поиска: https://www.linkedin.com/search/results/people/?keywords=Business%20Development&origin=SWITCH_SEARCH_VERTICAL
Затем я могу перейти на первую сторону, прокрутить вниз (бесконечная прокрутка),нажмите «Далее», что прекрасно работает, но затем на странице 2 он не прокручивается.Я уже понял, что URL не обновляется, добавив «& page = 2», поэтому переменные для прокрутки не обновляются.Я нашел другой способ сделать это - мне просто интересно, где я ошибся, кто-нибудь из профессионалов, чтобы исправить этот сценарий?
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.common.exceptions import NoSuchElementException
from time import sleep
userid = 'myemail@mail.com'
password = 'secret'
driver = webdriver.Chrome()
driver.get('https://www.linkedin.com')
driver.find_element_by_xpath("""//*[@id="login-email"]""").send_keys(userid)
driver.find_element_by_xpath("""//*[@id="login-password"]""").send_keys(password)
driver.find_element_by_xpath("""//*[@id="login-submit"]""").click()
driver.get('https://www.linkedin.com/search/results/people/?keywords=Business%20Development&origin=SWITCH_SEARCH_VERTICAL')
while True:
SCROLL_PAUSE_TIME = 0.5
# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
print('current url' + driver.current_url)
while True:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
print('new height ' + str(new_height))
if new_height == last_height:
break
last_height = new_height
driver.find_element_by_xpath("""//button[@class='artdeco-pagination__button artdeco-pagination__button--next artdeco-button artdeco-button--muted artdeco-button--icon-right artdeco-button--1 artdeco-button--tertiary ember-view' and contains(.,'Next')]""").click()