安装chrome-browser
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --no-check-certificate
sudo yum install google-chrome-stable_current_x86_64.rpm
yum install chromedriver
或者
wget http://chromedriver.storage.googleapis.com/112.0.5615.49/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver所在的文件夹
添加 test_selenium.py 的内容如下:
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
if name == "main":
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--window-size=2560,1600')
driver = Chrome(options=options)
driver.get('https://www.baidu.com/')
print(driver.page_source)
driver.save_screenshot("test.png")
driver.close()
driver.quit()
网友评论