1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
const puppeteer = require('puppeteer'); const fs = require('fs'); const path = require('path'); const https = require('https'); (async () => { const browser = await puppeteer.launch({headless: true, args: ['--window-size=814,896', '--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1']}); // launch browser in non-headless mode and set user agent to iPhone 13 const page = await browser.newPage(); await page.goto('https://skybox.blockadelabs.com/'); // Wait for 2 seconds await page.waitForTimeout(3000); // Find the button element on the page with the text "Confirm" and click it. // Find the button element on the page with the text "Confirm" and click it. const elements = await page.$x('//*[@id="radix-:R36ml9:"]/div[2]/button'); console.log('elements', elements) if (elements.length > 0) { await elements[0].click(); } console.log('input', 'input'); // Use page.$ to select the input element using the provided CSS selector const inputElement = await page.$('body > div.container.absolute.inset-x-0.bottom-12.z-50.w-full.max-w-5xl.sm\\:bottom-10 > form > div.flex.w-full.flex-wrap.justify-between.gap-2.sm\\:flex-nowrap > div.relative.w-full > input'); // Type the text "你好" into the input element await inputElement.type('Ultraman eats hot pot'); // Press the enter key await inputElement.press('Enter'); // hidden underline underline-offset-2 sm:block // disabled:opacity-20 // Intercept browser download and get download link // Wait for the .psv-loader-container element to become visible await page.waitForSelector('.psv-loader-container', { visible: true, timeout: 60*60*24*1000 }); console.log('完成') page.on('response', async (response) => { const contentType = response.headers()['content-type']; if (contentType.startsWith('image/')) { const url = response.url(); console.log('Image URL:', url); // Use Node.js built-in 'fs' module to write the image data to a file // Extract the filename from the URL using the path module const filename = path.basename(url); // Use the https module to send a GET request to the URL https.get(url, (response) => { // Create a write stream to the desired file location const file = fs.createWriteStream(`./${filename}.jpg`); // Pipe the response data to the file stream response.pipe(file); // Log a message when the download is complete file.on('finish', async () => { console.log(`Download complete: ${filename}`); // Close the browser and exit the system // Close the current page await page.close(); await browser.close(); process.exit(); }); // Use the nodemailer module to send an email with the downloaded image as an attachment }); } }); // Find the first button element inside the form element and click it await page.click('body > div.container.absolute.inset-x-0.bottom-12.z-50.w-full.max-w-5xl.sm\\:bottom-10 > form > div.flex.w-full.justify-between.border-b-2.border-black > div.flex.place-items-center.gap-4.sm\\:gap-5 > button:nth-child(1)'); // Intercept the download by listening to the 'response' event of the page object // Filter the responses to only include those with a content-type of 'image' // Extract the URL of the image from the response and log it to the console })(); |