搜索await page.waitForSelector(allResultsSelector);
/**
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ /**
* @fileoverview Search developers.google.com/web for articles tagged
* "Headless Chrome" and scrape results from the results page.
*/ 'use strict'; const puppeteer = require('puppeteer'); (async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage(); await page.goto('https://developers.google.com/web/');
// Type into search box.---输入文字 还有提换方法
//await page.focus('#kw');
//await page.keyboard.sendCharacter('狗');
await page.type('#searchbox input', 'Headless Chrome'); // Wait for suggest overlay to appear and click "show all results".
const allResultsSelector = '.devsite-suggest-all-results';
//等待元素加载
await page.waitForSelector(allResultsSelector);
await page.click(allResultsSelector); // Wait for the results page to load and display the results.
const resultsSelector = '.gsc-results .gsc-thumbnail-inside a.gs-title';
await page.waitForSelector(resultsSelector); // Extract the results from the page.
const links = await page.evaluate(resultsSelector => {
const anchors = Array.from(document.querySelectorAll(resultsSelector));
return anchors.map(anchor => {
const title = anchor.textContent.split('|')[0].trim();
return `${title} - ${anchor.href}`;
});
}, resultsSelector);
console.log(links.join('\n')); await browser.close();
})();
搜索await page.waitForSelector(allResultsSelector);的更多相关文章
- puppeteer(三)常用API
1.Puppeteer 简介 Puppeteer 是一个node库,他提供了一组用来操纵Chrome的API, 通俗来说就是一个 headless chrome浏览器 (当然你也可以配置成有UI的,默 ...
- puppeteer:官方出品的chrome浏览器自动化测试工具
puppeteer发布应该有一段时间了,这两天正好基于该工具写了一些自动化解决方案,在这里抛砖引给大家介绍一下. 官方描述: Puppeteer is a Node library which pro ...
- ant design pro (十二)advanced UI 测试
一.概述 原文地址:https://pro.ant.design/docs/ui-test-cn UI 测试是项目研发流程中的重要一环,有效的测试用例可以梳理业务需求,保证研发的质量和进度,让工程师可 ...
- 关于Puppeteer的那些事儿
最近开始上手一个自动化测试工具Puppeteer,来谈一谈关于它的一些事儿. Puppeteer中文文档:https://zhaoqize.github.io/puppeteer-api-zh_CN/ ...
- 【基于Puppeteer前端自动化框架】【二】PO模式,断言(如何更简便逻辑的写测试代码)
一.概要 前面介绍了Puppeteer+jest+TypeScript做UI自动化,但是这知识基础的,我们实现自动化要考虑的很多,比如PO模式,比如配置文件,比如断言等等.下面就来一一实现我是怎么用p ...
- 【PUPPETEER】初探之执行JavaScript方法(六)
一.知识点 page.evaluate() document.querySelector().value = ''; 二.解析知识点 page.evaluate(),查看puppeteer 的api ...
- 微软最强 Python 自动化工具开源了!不用写一行代码!
1. 前言 最近,微软开源了一款非常强大的 Python 自动化依赖库:playwright-python 它支持主流的浏览器,包含:Chrome.Firefox.Safari.Microsoft E ...
- 推荐一款最强Python自动化神器!不用写一行代码!
搞过自动化测试的小伙伴,相信都知道,在Web自动化测试中,有一款自动化测试神器工具: selenium.结合标准的WebDriver API来编写Python自动化脚本,可以实现解放双手,让脚本代替人 ...
- 推荐一款最强Python自动化神器!再也不用写代码了!
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理 搞过自动化测试的小伙伴,相信都知道,在Web自动化测试中,有一款自动化测试神器工具: seleniu ...
随机推荐
- HTMLUNIT另一种注册方法
1 环境搭建: 1)下载 从链接:http://sourceforge.net/projects/htmlunit/files/htmlunit/ 下载最新的bin文件 2)关于bin文件 里面主要包 ...
- String方法阅读笔记
String类常用方法 1.int Length(): 参数:无 返回值:调用此方法的字符串的长度(int) 实例: public class Test { public static void ma ...
- Jmeter-maven-plugin github 版本插件变更历史
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md
- 20199317 myod实验
myod实验 实验内容: 1 复习c文件处理内容 2 编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能 3 main与其他分开,制作静态库和动态库 4 编写Mak ...
- html5 postMessage 消息传递问题
<script type="text/javascript"> $.fn.extend({ addEvent: function (type, handle, bool ...
- lable 语句
var is = 20; loop: while(is > 10){ console.log(is); if(is % 7 == 0){ break loop; } is --; } 结果: b ...
- 折腾前端条形码(Barcode)扫描识别, 笔记
barcode @zxing/library 方案 本地勉强把 Demo 在 React 里面跑通, 但是不好控制开始结束, API 不明确.实际识别率很低. 我是用手机屏幕放的条形码, 大概也有影响 ...
- selenium webdriver 执行Javascript
@Test public void testElementByID() { //通过JS获取页面元素 driver.get(url); driver.manage().window().maximiz ...
- LeetCode 24. Swap Nodes in Pairs(交换链表中每两个相邻节点)
题意:交换链表中每两个相邻节点,不能修改节点的val值. 分析:递归.如果以第三个结点为头结点的链表已经两两交换完毕(这一步递归实现---swapPairs(head -> next -> ...
- SpringBoot--⼯具表达式对象
⼯具表达式对象除了这些基本的对象之外,Thymeleaf将为我们提供⼀组⼯具对象,这些对象将帮助我们在表达式中执⾏常⻅任务.#execInfo:有关正在处理的模板的信息.#messages:⽤于在变量 ...