selemium环境准备

查找对应版本的chrome driver: http://chromedriver.chromium.org/downloads
解决DevToolsActivePort file doesn't exist: https://cloud.tencent.com/developer/article/1404558

测试代码:
    public static void main(String[] args) {
        // System.setProperty("webdriver.chrome.driver", "/Users/junhao.zhang/Downloads/chromedriver");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");
        options.setHeadless(true);
        Proxy proxy = new Proxy();
        proxy.setHttpProxy("proxy.com:8080");
        options.setProxy(proxy);
        ChromeDriver driver = new ChromeDriver(options);
        // driver.get("https://selenium.dev");
        driver.get("http://www.baidu.com");
        // driver.get("http://sports.sina.com.cn");
        System.out.println("Title: " + driver.getTitle());
        driver.quit();  
    }

对应的Dockerfile:
FROM registry-hulk.xxx.com/xxx/centos:offline_java_191206_centos7
MAINTAINER xxx.yyy "xxx.yyy@zzz.com"
RUN yum install -y google-chrome-stable
RUN /bin/wget https://chromedriver.storage.googleapis.com/73.0.3683.68/chromedriver_linux64.zip -O /usr/local/bin/chromedriver_linux64.zip
RUN cd /usr/local/bin/ && /bin/unzip chromedriver_linux64.zip && rm chromedriver_linux64.zip
ENV PATH /usr/local/bin:$PATH
 

selemium不适合做全网爬虫,只适合做app内h5/native以及特定web站点的抓取,因为它无法优雅地获取浏览器内部状态,比如http response code,比如网络连接是否有问题.

### Selenium 版本列表及发布日期 Selenium 自首次推出以来经历了多次迭代和发展,以下是部分重要版本及其发布时间: - **Selenium 1.0** 发布于2006年,在这一年 Google 工程师 Simon Stewart 启动了 WebDriver 项目[^1]。尽管最初并非作为 Selenium 的一部分开发,WebDriver 最终成为了 Selenium 测试框架的重要组成部分。 - **Selenium 2.0 (Selenium WebDriver)** 正式版发布于2011年7月8日。这一版本标志着 Selenium 和 WebDriver 的正式融合,带来了更强大的功能和支持更多种编程语言绑定的能力。 - **Selenium 3.0** 推出于2016年9月,此更新引入了一些重要的变化,比如 Firefox 浏览器驱动被独立出来处理[^3]。这意味着开发者需要单独安装特定的驱动程序才能继续使用该浏览器进行自动化测试工作。 - **Selenium 4.0** GA(General Availability) 版本最终定档在2021年10月5日。新特性包括但不限于改进了对现代Web应用的支持、增强了网络条件模拟等功能,并且进一步优化了API设计以提高易用性和性能表现。 对于具体的次要版本以及补丁级别的变更记录,则通常可以在官方GitHub仓库或者文档网站上找到详细的发行说明文件获取最新信息。 ```python import requests from bs4 import BeautifulSoup def get_selenium_versions(): url = 'https://www.selenium.dev/downloads/' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') versions = [] for item in soup.select('.release-version'): version_info = { 'version': item.a.string.strip(), 'date': item.span.string.split(' ')[0].strip() } versions.append(version_info) return versions print(get_selenium_versions()) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值