puppeteer執行js_使用Node.js和Puppeteer與表單和網頁進行交互– 2

puppeteer執行js

Hi guys! Today let's look at another powerful function of the puppeteer API using Node.js part 2.

嗨,大家好! 今天,讓我們看看使用Node.js第2部分的puppeteer API的另一個強大功能。

In the first part of this section, was talking about commands for keystroke control and typing as we'll normally do with an opened browser.

在本節的第一部分中,我們將討論鍵盤控制和鍵入的命令,就像我們通常在打開的瀏覽器中所做的那樣。

Here's the link to part 1: INTERACTING WITH FORMS AND WEB PAGES USING NODE-JS AND PUPPETEER- 1

這是第1部分的鏈接: 使用NODE-JS和PUPPETEER-1與表單和網頁進行交互

Imagine for a moment if it's possible to open a website, log in and take a screenshot of your dashboard.

想象一下,如果有可能打開一個網站,登錄并為您的儀表板截屏。

?????

??????

Take Note! You should have Node-js and puppeteer installed in your PC.

做記錄! 您應該在PC中安裝Node-js和puppeteer。

With Node-js and puppeteer already up and running, let's get started.

在Node-js和puppeteer已啟動并運行的情況下,讓我們開始吧。

*NB: If you don't yet have Node-js/ puppeteer installed in your PC, read the article NODE & GOOGLE PUPPETEER API SERIES

*注意:如果您的PC尚未安裝Node-js / puppeteer,請閱讀文章NODE&GOOGLE PUPPETEER API SERIES

Today, let's continue from our last part where we saw how to type o fill the form.

今天,讓我們從最后一部分繼續,在那里我們看到了如何鍵入o填寫表格。

Now let's see how to submit..

現在讓我們看看如何提交。

But there's a problem!!!! Most often, the submit button has no id or class.

但是有一個問題! 通常,提交按鈕沒有ID或類。

Indeed, the puppeteer has made work easy for you and me.

的確,木偶使您和我的工作變得輕松。

Let's see how this can be done.

讓我們看看如何做到這一點。

Now, let's get started.

現在,讓我們開始吧。

Since we can't get the id or class of the submit button from inspecting, we will use a command on the web browser's console which will return what we'll use at the place of id/class.

由于無法通過檢查獲取提交按鈕的ID或類,因此我們將在Web瀏覽器的控制臺上使用命令,該命令將返回我們將在ID /類位置使用的命令。

Open your browser, move to the console and type

打開瀏覽器,移至控制臺并輸入

    document.querySelectorAll('input[type="submit"]') [0]

Interacting with forms and web pages 4

It's going to output the input type and value of your own submit button.

將輸出您自己的提交按鈕的輸入類型和值。

Use the input type at the await.page.click parameter as seen in the code below.

使用await.page.click參數中的輸入類型,如下面的代碼所示。

Open a text editor and type the following code and save it with the file name app.js:

打開一個文本編輯器,輸入以下代碼,并將其保存為文件名app.js

The code below fills the form and submits and takes a screenshot of action after submitting.

下面的代碼填寫了表單,然后提交并在提交后對操作進行了截圖。

const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('file:///H:/js-form-validator-master/index.html')
// focus on the element with id  specified in bracket
await page.focus('#example-1-name') 
// types the sentence in bracket 
await page.keyboard.type('ENGINEER GODWILL') 
await page.focus('#example-1-email') 
await page.keyboard.type('[email?protected]')
await page.focus('#example-1-password')
await page.keyboard.type('admin123')
// clicks on the submit button of the form
await page.click ('input[type="submit"]') 
// captures a screenshot
await page.screenshot({ path: 'keyboard.png' }) 
console.log ('done');
await browser.close()
})()

NB: You can use any URL of your choice,

注意:您可以使用任何選擇的URL,

I this example, I used a webpage that was already downloaded to facilitate the tutorial but if it concerns a URL on the www, internet connection is required to navigate to the website/web page.

在本示例中,我使用已經下載的網頁來簡化本教程,但是如果它涉及www上的URL,則需要互聯網連接才能導航到該網站/網頁。

The file should be saved in your default Node-js directory.

該文件應保存在默認的Node-js目錄中。

Run the code by initiating the file at the command prompt like a regular Node-js file.

通過在命令提示符處啟動文件(如常規Node-js文件)來運行代碼。

The Screenshot ( image file) is then stored in the default Node-js directory with name keyboard.png

屏幕快照(圖像文件)然后存儲在名稱為keyboard.png的默認Node-js目錄中。

Output image file:

輸出圖像文件:

Interacting with forms and web pages 5

翻譯自: https://www.includehelp.com/node-js/interacting-with-forms-and-web-pages-using-node-js-and-puppeteer-2.aspx

puppeteer執行js

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542808.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542808.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542808.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

好用的平板電腦_小熊分享|這五款平板電腦的性價比絕了!

【葉紫網】獨樂樂不如眾樂樂,點擊上方頭像并添加關注,與葉紫科技小熊一起探索科技的奧秘。要說當代年輕人的消費觀,我們也是說要該花花,該省省,像現在的科技產品更新換代的速度,就算我們的荷包相當的鼓&…

python if語句 for語句 while語句

python基礎語法3if語句for循環while循環else語句退出循環if語句 執行條件判斷,符合執行if內語句,否則執行elif或者else。 if、elif、else都要接冒號,注意縮進 各級條件互斥 后面的條件可以接列表,表示或關系 contribution860 if…

交際過程的兩個基本環節_跨文化交際學概論筆記(二)

第二部分 基本概念:文化與交際第一章 文化的定義與特征一、文化的定義1. 文化的定義為何重要首先,在跨文化交際學中文化是一個至關重要的問題。研究時,不可避免進行文化對比。其次,在研究任何學科前,術語的界定是前提。…

Python中列表的del,remove和pop函數之間的區別

1)Python del函數 (1) Python del function) del is nothing but "delete". del is a keyword which basically goes on the position given by the user in del(position) and deletes that element and also changes the positions of all the other elements as i…

lcd圖片轉二進制工具_遼寧2.8寸LCD屏價格,測距儀LCD顯示屏_思邁微

首頁 > 新聞中心發布時間:2020-11-15 08:27:09 導讀:思邁微為您提供遼寧寸LCD屏價格,測距儀LCD顯示屏的相關知識與詳情: 以上便是對LED點陣式顯示屏的軟硬件系統、組成等的技術知識的粗略的介紹。以這款名為《液晶顯示器亮點壞點修復工具》…

python 布爾值 布爾運算 運算符

python基礎語法4布爾值布爾運算運算符算術運算符賦值運算符比較運算符邏輯運算符布爾值 布爾值:Ture(真) Flase(假) 假:Flase、0、’’(空字符串)、[](空列表&#xff0…

python代碼安全性問題_這個python代碼對注入安全嗎?

我在Python中有一個服務器/客戶機套接字對。服務器接收特定的命令,然后準備響應并將其發送到客戶端。在在這個問題中,我關心的只是代碼中的可能的注入:如果可以要求服務器對第二個參數做一些奇怪的事情——如果對命令內容的控制不足以避免不希…

Python | 使用+ =運算符在字符串末尾附加文本

Given a string, and we have to append more string (text) at the end of the string using operator in Python. 給定一個字符串,我們必須在Python中使用 運算符在字符串的末尾附加更多字符串(文本)。 There are two methods to add string (text) at the end …

ps如何修改圖片大小尺寸_PS新手入門教程:學習如何修改畫布的大小

PS新手入門教程:學習如何修改畫布的大小。在photoshop中,可以把畫布理解為一張白紙,而我們要處理的圖像可以理解為這張白紙表面上的畫。我們修改畫布的大小時,圖像并不會隨著畫布的大小而整體變大或縮小,這是修改畫布大…

jfinal poi

2019獨角獸企業重金招聘Python工程師標準>>> 最近項目采用jfinal的項目要對一些excel進行操作,經過考慮采用jfinalpoi,在一些學習,使用后總結并分享一些代碼片段。 導入excel protected Workbook workbook null;protected File filenull;publ…

python 函數 類 模塊

python基礎語法5函數作用域函數參數函數對象無名函數回調函數函數嵌套類類的創建類的調用初始化方法類的繼承類的定制模塊使用模塊函數 封裝好,進行某種功能 del 函數名(參數):函數體return 返回值(可以沒有return語句)作用域 …

activemq nodejs stomp 重連機制_5分鐘優劣分析 Kafka、RabbitMQ、RocketMQ、ActiveMQ消息隊列...

一、資料文檔Kafka:中,有kafka作者自己寫的書,網上資料也有一些。 rabbitmq:有一些不錯的書,網上資料多。 zeromq:少。沒有專門寫zeromq的書,網上的資料多是一些代碼的實現和簡單介紹。 rocketm…

excel保存快捷鍵_干貨 | 快速提高工作效率的電腦快捷鍵!

點擊標題下「藍色微信名」可快速關注隨著科學技術的發展,電腦已經成為每個人生活和工作的必備工具。然而,很多人在使用電腦的過程中非常依賴鼠標,導致雙手需要頻繁離開鍵盤,造成工作間歇中斷,導致用電腦處理工作的效率…

16位的數字高字節和低字節_掩蓋8位數字的較低和較高半字節| 8085微處理器

16位的數字高字節和低字節Problem statement: 問題陳述: To mask lower and higher nibble of 8-bit number using 8085 Microprocessor. 使用8085微處理器掩蓋8位數字的較低和較高半字節。 Algorithm: 算法: Load the content of accumulator A with…

釘釘 ISV 應用開發的一些心得

1. 背景 前段時間從前到后完整地做完了一個簡單的釘釘上的 ISV 應用 —— 猿活動。 最開始想做這么一個小工具,是想到,平時部門中經常會組織一些分享活動,但是這些分享活動卻沒有一個比較直觀的“站點”來記錄一次又一次的,很多人…

mcq 隊列_MCQ | 8086微處理器中的字符串操作指令

mcq 隊列Question 1: 問題1: A string is a collection of characters. Each Character is an of byte length which is stored at successive locations. In the 8086 microprocessor, which characters are considered in the string? 字符串是字符的集合。 每…

python 編碼 解碼 讀寫文件

python基礎語法6編碼解碼encode編碼與decode解碼讀寫文件編碼解碼 計算機是以二進制(0或1)存儲的,以字節為單位,1byte8bit,1KB1024B;1MB1024KB;1GB1024MB 編碼表:ASCII碼&#xff0…

電腦如何設置不休眠_電腦休眠了卻沒法喚醒?設置一下就好!

關注全新【HP惠課廳】,惠普消費新品全知曉逐步復工,辦公室環境又漸漸熟悉了起來午休外出吃飯、忙里偷閑散步、下班不想關電腦……隨手就把電腦休眠了開機也快,網頁和工作內容也不會被關掉休眠功能是挺好用的可有時候,無論怎么點開…

node+bower+gulp+webpack初見

2019獨角獸企業重金招聘Python工程師標準>>> node node模塊管理是通過NPM(即 Node Package Manage,是 NodeJS 模塊管理工具)來處理各模塊之間的依賴。NPM按樹狀結構來管理的,支持某模塊的不同版本。 [前提是本機已安裝…

Java LinkedList公共布爾boolean offerFirst(Object o)方法(帶示例)

LinkedList公共布爾布爾offerFirst(Object o)方法 (LinkedList public boolean offerFirst(Object o) method) This method is available in package java.util.LinkedList.offerFirst(Object o). 軟件包java.util.LinkedList.offerFirst(Object o)中提供了此方法。 This metho…