
有的页面打开有个按钮是不可点击,要延时几秒才会变成可点击状态,然后要处理点击后的页面。比如这个 https://ouo.io/go/yq25z
from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, 'btn-main'))) element.click() 在无图形界面的 Ubuntu Server 上运行,加了chrome_options.add_argument('--headless')就不工作,加上 time.sleep(15)也不行。
在 macOS 上运行,不加--headless ,每次运行自动打开 Chrome 就能正常处理后续的工作。
请问怎么让它在无图形界面的环境也能工作?
1 jjplay 2023 年 7 月 11 日 装虚拟屏幕 xvfb |
3 wgit 2023 年 7 月 11 日 不是可以等待某个元素吗 等待多少秒,然后间隔多久检查一次 还能基于标签属性 去判断按钮是否是可用状态 |
6 girl1462235 2023 年 7 月 11 日 其实。。。 你设置一个 UserAgent 就好了 |
7 girl1462235 2023 年 7 月 11 日 |
8 yaleyu OP @girl1462235 哎,真的行,看来页面做了一定的反爬,有头时候是真正打开浏览器,无头时候被反爬了 |