[英]How do I get the next row of database results from a button click using Node.js?
[英]How do I click a button on a website using Requests in Node JS
我想在這個頁面點擊測試產品: https://biscuit-bird.myshopify.com/collections/all
我正在嘗試 go 完全基於請求,而不是使用像 puppeteer 或僵屍這樣的無頭瀏覽器,因為我已經這樣做了。
請通過發送請求讓我知道如何執行此操作。
我假設你正在使用這個庫? https://github.com/request/request
If so, inside a callback function that provides body
of the page, you can use some lib to parse HTML content, find your link to a test product with CSS selector, and then open the URL stored in href
.
這個剪斷對我有用:
const request = require('request');
var HTMLParser = require('node-html-parser');
request({
url:'https://biscuit-bird.myshopify.com/collections/all',
headers: {
'User-Agent':'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1'
}
}, function (error, response, body) {
// parse method returns a root of the generated DOM
const root = HTMLParser.parse(body)
// similarly to the browser's DOM, you can lookup DOM elements by their selector using method querySelectorAll
const links = root.querySelectorAll("a.grid-link")
const href = links[0].getAttribute('href');
// @TODO: send another request to the URL defined in `href`
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.