为什么在 modal/popup 上滚动在 Instagram 上不起作用
Why scroll on modal/popup doesn't working on instagram
我很尴尬,因为我没有在 Instagram 的模式上滚动。而不是它滚动背面的页面:(
我已经尝试过 browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", modalDiv)
...我尝试过我创建的任何东西,但仍然无法正常工作。
我的代码:
browser.get('https://www.instagram.com/%s' % account)
sleep(2)
clickToFollowing= browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a/span")
clickToFollowing.click()
actionChain = webdriver.ActionChains(browser)
time.sleep(2)
modalDiv= browser.find_elements_by_xpath("//html/body/div[5]/div/div/div[2]/div/div/div[4]/div[2]/div[2]")
browser.execute_script("window.scrollBy(0, 660);")
您需要在关注者列表部分多次滚动才能获取所需的一切。
代码:
options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
driver = webdriver.Chrome("C:\Users\etc\Desktop\Selenium+Python\chromedriver.exe", options=options)
wait = WebDriverWait(driver, 30)
driver.get("https://www.instagram.com")
wait.until(EC.element_to_be_clickable((By.NAME,"username"))).send_keys('your username')
wait.until(EC.element_to_be_clickable((By.NAME,"password"))).send_keys('your password')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button[type='submit']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//button[text()='Not Now']"))).click()
sleep(3)
wait.until(EC.element_to_be_clickable((By.XPATH,"//button[text()='Not Now']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//*[name()='svg' and @aria-label='Activity Feed']/../../following-sibling::div/span"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Profile']"))).click()
sleep(3)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@title='Change Profile Photo']/../../../following-sibling::section/descendant::li[3]/a"))).click()
sleep(3)
fBody = driver.find_element_by_xpath("//div[@class='isgrP']")
scroll = 0
while scroll < 5: # scroll 5 times
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', fBody)
sleep(2)
scroll += 1
fList = driver.find_elements_by_xpath("//div[@class='isgrP']//li")
print("fList len is {}".format(len(fList)))
print("ended")
我很尴尬,因为我没有在 Instagram 的模式上滚动。而不是它滚动背面的页面:(
我已经尝试过 browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", modalDiv)
...我尝试过我创建的任何东西,但仍然无法正常工作。
我的代码:
browser.get('https://www.instagram.com/%s' % account)
sleep(2)
clickToFollowing= browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a/span")
clickToFollowing.click()
actionChain = webdriver.ActionChains(browser)
time.sleep(2)
modalDiv= browser.find_elements_by_xpath("//html/body/div[5]/div/div/div[2]/div/div/div[4]/div[2]/div[2]")
browser.execute_script("window.scrollBy(0, 660);")
您需要在关注者列表部分多次滚动才能获取所需的一切。
代码:
options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
driver = webdriver.Chrome("C:\Users\etc\Desktop\Selenium+Python\chromedriver.exe", options=options)
wait = WebDriverWait(driver, 30)
driver.get("https://www.instagram.com")
wait.until(EC.element_to_be_clickable((By.NAME,"username"))).send_keys('your username')
wait.until(EC.element_to_be_clickable((By.NAME,"password"))).send_keys('your password')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button[type='submit']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//button[text()='Not Now']"))).click()
sleep(3)
wait.until(EC.element_to_be_clickable((By.XPATH,"//button[text()='Not Now']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//*[name()='svg' and @aria-label='Activity Feed']/../../following-sibling::div/span"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Profile']"))).click()
sleep(3)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@title='Change Profile Photo']/../../../following-sibling::section/descendant::li[3]/a"))).click()
sleep(3)
fBody = driver.find_element_by_xpath("//div[@class='isgrP']")
scroll = 0
while scroll < 5: # scroll 5 times
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', fBody)
sleep(2)
scroll += 1
fList = driver.find_elements_by_xpath("//div[@class='isgrP']//li")
print("fList len is {}".format(len(fList)))
print("ended")