3 回答
TA贡献1895条经验 获得超7个赞
这有效吗?我也是硒的新手。不过,我在这里find_element_by_xpath改为find_element_by_class_name。
from selenium.webdriver.common.action_chains import ActionChains
def business_description_scrapper():
u = "https://teqatlas.com/products-and-services/0chain"
browser = webdriver.Chrome(executable_path=binary_path)
wait = WebDriverWait(browser, 10)
browser.set_page_load_timeout(10)
# stop load after a timeout
try:
browser.get(u)
except TimeoutException:
browser.execute_script("window.stop();")
button = browser.find_element_by_class_name("o5ph61-3.eBqrHG")
if button:
actions = ActionChains(browser)
actions.click(button).perform()
business_description_scrapper()
我测试了它,按钮被点击了。
TA贡献1786条经验 获得超11个赞
您正在使用的 x 路径不正确。请选择以下 xpath 以单击按钮:
WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, "//button[text()='Advisories']"))).click()
您需要添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
TA贡献1829条经验 获得超7个赞
from selenium import webdriver
import pandas as pd
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('--headless')
driver = webdriver.Firefox(options=options)
driver.get("https://teqatlas.com/products-and-services/0chain")
btn = driver.find_element_by_css_selector("button.o5ph61-3.faMQuX").click()
df = pd.read_html(driver.page_source)[0]
df.to_csv("data.csv", index=False)
driver.quit()
输出:在线查看
添加回答
举报