试图使用python上的硒滚动弹出弹出式弹出弹出时,对象无法相互作用
我需要向下滚动以下链接中出现的弹出窗口 https://www.vivino.com/it/en/en/rronchi-di-cialla-picolit-di-cialla/w/2015576?year=2011&pprice_id = 23500586 (或Vivino上的任何其他葡萄酒链接)单击“显示更多评论”后,但是当我尝试滚动时,我会发现元素无法相互作用的错误。 弹出评论的代码是以下
from urllib.request import urlretrieve
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
import csv
import re
import time
import random
target_url = 'https://www.vivino.com/IT/it/ronchi-di-cialla-picolit-di-cialla/w/2015576?year=2011&price_id=23500586'
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options=options)
driver.get(target_url) #apre la pagina
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/3);")
time.sleep(1)
driver.execute_script("window.scrollTo(document.body.scrollHeight/3, document.body.scrollHeight*2/3);")
time.sleep(1)
driver.execute_script("window.scrollTo(document.body.scrollHeight*2/3, document.body.scrollHeight);")
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
driver.find_element(By.CSS_SELECTOR, "button[class='MuiButtonBase-root MuiButton-root jss1 MuiButton-outlined jss3 MuiButton-disableElevation']").click()
I need to scroll down a pop up that appears in the following link https://www.vivino.com/IT/en/ronchi-di-cialla-picolit-di-cialla/w/2015576?year=2011&price_id=23500586 (or any other wine link on vivino) after clicking on 'show more reviews', but when i try to scroll i get the Element not Interactable error.
The code to open the reviews pop up is the following
from urllib.request import urlretrieve
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
import csv
import re
import time
import random
target_url = 'https://www.vivino.com/IT/it/ronchi-di-cialla-picolit-di-cialla/w/2015576?year=2011&price_id=23500586'
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options=options)
driver.get(target_url) #apre la pagina
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/3);")
time.sleep(1)
driver.execute_script("window.scrollTo(document.body.scrollHeight/3, document.body.scrollHeight*2/3);")
time.sleep(1)
driver.execute_script("window.scrollTo(document.body.scrollHeight*2/3, document.body.scrollHeight);")
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
driver.find_element(By.CSS_SELECTOR, "button[class='MuiButtonBase-root MuiButton-root jss1 MuiButton-outlined jss3 MuiButton-disableElevation']").click()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是每1秒钟向下滚动到每个评论的代码。我建议您不要直接在评论上循环,即不要做类似的事情
,因为最初只加载了很少的评论,然后随着您向下滚动时,会加载更多的评论。因此,如果您使用上述代码
评论
将仅包含第一个加载的评论。下面的代码解决了此问题,但是如果总评论的数量小于limit
,则将失败。因此,您应该改进代码以考虑到这一事实Here is the code scrolling down to each review every 1 second. I suggest you to not loop directly on reviews, i.e. don't do something like
because initially only few reviews are loaded, and then as you scroll down more are loaded. So if you use the code above
reviews
will only contain the first loaded reviews. The code below solves this problem, but it will fail if the number of total reviews is smaller thanlimit
. So you should improve the code to take into account also this fact