时间:2021-11-25来源:www.pcxitongcheng.com作者:电脑系统城
我这里是工作需要把selenium 爬虫程序部署到Linux 服务器上面 顺便跟大家交流一下 如果有兴趣的话可以看一下
Selenium是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样, 爬虫用它来抓取一些js动态加载的数据
代码如下
| 1 2 3 4 5 6 7 8 9 10 11 12 |
from selenium.webdriver import Chromefrom selenium.webdriver.chrome.service import Servicefrom selenium.webdriver.chrome.options import Options # 使用无头浏览器from selenium.webdriver import ChromeOptionschrome_options = Options()options = ChromeOptions()options.add_experimental_option('excludeSwitches', ['enable-automation']) # =>去掉浏览器正在受到自动测试软件的控制options.add_experimental_option('useAutomationExtension', False)chrome_options.add_argument("--headless") # => 为Chrome配置无头模式chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--disable-gpu')chrome_options.add_argument('--disable-dev-shm-usage') |
代码如下:
| 1 2 3 4 5 6 |
s = Service(r"/home/driver/chromedriver")driver = Chrome( service=s, options=chrome_options ) driver.get("https://www.baidu.com") print(diiver.title) |
命令如下:
| 1 2 3 |
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm检查chrome的版本google-chrome --version |
命令如下:
| 1 2 3 4 5 6 7 8 |
按照对应的chrome版本下载chromedriver驱动地址: https://npm.taobao.org/mirrors/chromedriver我的版本号是: 96.0.4664.45wget https://npm.taobao.org/mirrors/chromedriver/96.0.4664.45/chromedriver_linux64.zip yum install -y unzip zipunzip chromedriver_linux64.zip # 解压zip文件mkdir driver #新建文件夹用来存放驱动chmod 777 driver/chromedriver # 这是权限 我这里给的是 777 |
新建test.py文件
| 1 | vi test.py |

保存 test.py run 一下看看

看到这个我么就算请求成功了
到此这篇关于在linux系统下部署selenium爬虫程序介绍的文章就介绍到这了
2024-07-07
myeclipse怎么导入tomcat教程2024-07-07
myeclipse如何启动tomcat2024-07-07
myeclipse如何绑定tomcat上线了一个小的预约程序,配置通过Nginx进行访问入口,默认的日志是没有请求时间的,因此需要配置一下,将每一次的请求的访问响应时间记录出来,备查与优化使用....
2023-03-17