英文:
Puppeteer cannot read a classname with spaces
问题
无法阅读类名中包含空格的原因,但可以读取ID或名称是因为 Puppeteer 不支持使用类名中的空格作为选择器。需要帮助的话,你可以尝试使用有效的 CSS 选择器或其他属性来选择元素。
英文:
Someone tell me why puppeteer cannot readme a classname with spaces, but a id or name it's works. I need help, i just make a simple automation.
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto("https://www.reddit.com/")
await page.click("._3Wg53T10KuuPmyWOMWsY2F Z_HUY3BUsGOBOtdmH94ZS q_unSaY23rpdd3lDvGZ- _2iuoyPiKHN3kfOoeIQalDT _10BQ7pjWbeYP63SAPNS8Ts HNozj_dKjQZ59ZsfEegz8 _2Z-LWN_PrkTncEM_mPuEW5")
})();
答案1
得分: 2
在Puppeteer中,当使用page.click()方法通过类名选择元素时,不应在类名之间包含任何空格。相反,应该将类名连接在一起,不使用空格。
你应该这样写:
await page.click("._3Wg53T10KuuPmyWOMWsY2F.Z_HUY3BUsGOBOtdmH94ZS.q_unSaY23rpdd3lDvGZ-._2iuoyPiKHN3kfOoeIQalDT._10BQ7pjWbeYP63SAPNS8Ts.HNozj_dKjQZ59ZsfEegz8._2Z-LWN_PrkTncEM_mPuEW5")
英文:
In Puppeteer, when using the page.click() method to select an element by its class name, you should not include any spaces between the class names. Instead, you should concatenate the class names together without spaces.
You should write:
await page.click("._3Wg53T10KuuPmyWOMWsY2F.Z_HUY3BUsGOBOtdmH94ZS.q_unSaY23rpdd3lDvGZ-._2iuoyPiKHN3kfOoeIQalDT._10BQ7pjWbeYP63SAPNS8Ts.HNozj_dKjQZ59ZsfEegz8._2Z-LWN_PrkTncEM_mPuEW5")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论