如何解决硒未装载在聚会技术中显示更多
我花了近几天的时间来解决这个问题,但没有成功:(有人可以帮忙吗?基本上是在metup网站上针对给定城市的内容,当硒单击“显示更多”时,它会加载但没有任何显示,但是如果我这样做了手动在相同的链接上进行操作。任何帮助将不胜感激。PS我是新手,所以不要难:)
import pandas as pd
import numpy as np
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
import time
#here is a link to an excel file with links like:
#https://www.meetup.com/find/tech/?allMeetups=true&radius=5&userFreeform=Rio+de+Janeiro%2C+Brazil&mcId=c1002406&change=yes&sort=recommended&eventFilter=mysugg
df = pd.read_excel(r'G:\....\Cities_tech_try.xlsx')
df['Group_count'] = np.nan
for index,row in df.iterrows():
PATH = 'C:\\temp\\chromedriver_win32\\chromedriver.exe'
driver = webdriver.Chrome(PATH)
URL=row['Link']
driver.maximize_window()
driver.get(URL)
#driver.execute_script("document.body.style.zoom='80%'")
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
try:
time.sleep(1)
driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/div/div/div[2]/div[1]/div[2]/div/span').click()
time.sleep(5)
while True:
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
last_height = driver.execute_script("return document.body.scrollHeight")
time.sleep(5)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
df.loc[index,'Group_count'] = len(driver.find_elements_by_tag_name('h3'))
except NoSuchElementException:
df.loc[index,'Group_count'] = len(driver.find_elements_by_tag_name('h3'))
解决方法
尝试此代码
from selenium import webdriver
import time
url = 'https://www.meetup.com/find/?allMeetups=true&radius=100&userFreeform=Rio+de+Janeiro%2C+Brazil&mcId=c1002406&mcName=Rio+de+Janeiro%2C+BR&sort=recommended'
browser = webdriver.Chrome('C:\\seleniumDrivers\\chromedriver.exe')
getr = browser.get(url)
browser.maximize_window()
def clickonce():
time.sleep(3)
browser.execute_script("window.scrollTo(0,document.body.scrollHeight);")
time.sleep(5)
browser.find_element_by_xpath("//span[contains(text(),'Show more')]").click()
def scrolldown():
time.sleep(3)
browser.execute_script("window.scrollTo(0,document.body.scrollHeight);")
time.sleep(5)
clickonce()
while True:
scrolldown()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。