【发布时间】:2021-07-26 00:54:28
【问题描述】:
我想用“显示更多”按钮抓取谷歌学者页面。使用该平台的帮助解决我之前提出的问题,我编写了以下代码,以便单击“显示更多”按钮。但是,我仍然遇到问题。对于带有多个“显示更多”按钮的配置文件,只有第一个被点击。我不明白为什么会这样。我将不胜感激。
from selenium import webdriver
import time
from bs4 import BeautifulSoup
import pandas as pd
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
chrome_path = r"C:\Users\ish05\Desktop\python\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("https://scholar.google.com/citations?user=cp-8uaAAAAAJ&hl=en")
time.sleep(3)
show_more = driver.find_elements_by_tag_name('button')
for x in range(len(show_more)):
if show_more[x].is_displayed():
driver.execute_script("arguments[0].click();", show_more[x])
time.sleep(3)
【问题讨论】:
标签: javascript python selenium web-scraping xpath