目前,我的 puppeteer 文件中有以下部分代码:
const getImgSrc = await page.$eval('#ldpGallery', el => el.getElementsByTagName('img'));
console.log(getImgSrc);
Run Code Online (Sandbox Code Playgroud)
我从中得到的 html 是这样的:
<img data-src="https://example.com/981489624/e132d90154bc6cbc6616442c0742fc43l-m0xd-w1020_h770_q80.jpg" class="owl-lazy" src="">
Run Code Online (Sandbox Code Playgroud)
我在控制台中得到的结果是这样的:
{ '0': {},
'1': {},
'2': {},
'3': {},
'4': {} }
Run Code Online (Sandbox Code Playgroud)
我正在尝试从上面的 html 访问 data-src。在我检索到我尝试过的对象之后。forEach() 和 map ,它们都给我一个错误。
我将如何获得 data-src 字符串?
我有以下 HTML 结构
<div class ="container" id= "12">
<div class="details" desc-type= "multiline">
<a href="#">
<div class="description"> Some Description </div>
</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码抓取这个
const SELECTOR =
"div.container";
const movies = await page.$$eval(
SELECTOR,
nodes =>
nodes.map(element => {
return {
movieID: element.getAttribute("id"),
};
} )
);
Run Code Online (Sandbox Code Playgroud)
如何修改上面的代码,这样我可以阅读desc-type= "multiline"和innerText的<div class="description">?
我正在尝试使用 Puppeteer 自动执行查询该网站上的数据的任务。因此,我需要选择数据集(每日摘要,第一个选项),然后选择位置类型(州,第三个选项),然后选择州(阿拉斯加,第二个选项)。问题是我的代码没有更改为下一个表。因此,在选择数据集中的第一个选项(每日摘要)后,它不会选择第三个选项(州),而是再次选择数据集表中的第三个选项!我是 Puppeteer 的新手,所以我真的不知道该怎么做。任何帮助表示赞赏。
下面是我的代码:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless:false})
const page = await browser.newPage()
const navigationPromise = page.waitForNavigation()
await page.goto('https://www.ncdc.noaa.gov/cdo-web/datatools/selectlocation')
await page.waitForSelector('.selectLocationFilters > .datasetContainer > .slideElement > #datasetSelect > option:nth-child(1)')
await page.click('.selectLocationFilters > .datasetContainer > .slideElement > #datasetSelect > option:nth-child(1)')
await page.select('.inset #locationCategorySelect', '')
await page.waitForSelector('.selectLocationFilters > .locationCategoryContainer > .locationCategoryFilter > #locationCategorySelect > option:nth-child(3)')
await page.click('.selectLocationFilters > .locationCategoryContainer > .locationCategoryFilter > #locationCategorySelect > option:nth-child(3)')
await page.select('.inset #selectedState', '')
await …Run Code Online (Sandbox Code Playgroud)我在 Python 中使用 Playwright,我想将 javascript 注入到一个页面中,该页面监视 DOM 突变并触发自定义事件,并在 Python 中捕获这些事件。
这是一个 Python 脚本示例:
page.evaluate("//js code that essentially dispatches new CustomEvent('newPosts')")
page.on("newPosts", handle_posts)
Run Code Online (Sandbox Code Playgroud)
到目前为止,Python 端没有任何反应,就好像事件不存在一样。
如果我手动检查浏览器控制台,我可以看到事件在浏览器端触发得很好(我正在捕捉它)document.addEventListener('newPosts', fn)
python webautomation dom-events playwright playwright-python
我知道有很多问题与创建动态查询有关但没有人可以帮助我.我试图在循环cmd.Parameters.AddWithValue的帮助下创建一个动态,foreach但我找不到我传入的所有值foeach.我知道我正在写var values =""这就是值给我null价值的方式
我提供的代码可能会帮助您解决错误
public void insert_Para(System.Web.UI.HtmlControls.HtmlGenericControl ControlName, String TableName)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString()))
{
var values = "";
SqlCommand cmd = new SqlCommand("insert into "+ TableName +" values(" + values + ")", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
foreach (var item in ControlName.Controls)
{
if (item is TextBox)
{
cmd.Parameters.AddWithValue("@" + ((TextBox)item).ID, ((TextBox)item).Text);
values += "@" + ((TextBox)item).ID + ",";
}
}
if (con.State == ConnectionState.Closed)
con.Open();
cmd.ExecuteNonQuery(); …Run Code Online (Sandbox Code Playgroud) 我使用此代码来禁用页面加载中的图像,但不起作用:
_page = await _browser.NewPageAsync();
await _page.SetRequestInterceptionAsync(true);
// disable images to download
_page.Request += (sender, e) =>
{
if (e.Request.ResourceType == ResourceType.Image)
e.Request.AbortAsync();
else
e.Request.ContinueAsync();
};
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我对 Puppeteer 和 JS 非常陌生,但我想知道如何在网页上找到一个元素并在其周围绘制一个边界框,这样如果我进行屏幕截图,该框将可见(我想要整个页面的屏幕截图,但想要还可以查看边界框。
我正在学习itextsharp,我有什么问题吗?将文字嵌入pdf文件(水印)时如何隐藏文字?如果我成功嵌入,如何从嵌入的pdf文件中获取文本?对不起,我的英语水平最差。
我使用了“ TEXT_RENDER_MODE_INVISIBLE”,但文本出现在pdf文件中(可见)。这是我的代码:
PdfReader reader = new PdfReader("test.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileStream("testStamperPdf.pdf", FileMode.Create));
stamper.ViewerPreferences = PdfWriter.PageLayoutTwoColumnLeft;
PdfContentByte under;
BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
int total = reader.NumberOfPages;
for (int i = 1; i <= total; i++)
{
under = stamper.GetUnderContent(i);
under.BeginText();
under.SetFontAndSize(baseFont, 18);
under.ShowTextAligned(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE, "Stackoverflow", 200, 400, 45);
under.EndText();
}
stamper.Close();
Run Code Online (Sandbox Code Playgroud)
我不明白!!!
所以我做了 4 个函数,“所有”函数都在空数组上返回错误
--
myLength1 :: (Num b) => [a] -> b
mylength1 [] = 0
myLength1 (_:as) = 1 + myLength1 as
--
myLength2 :: [a] -> Integer
mylength2 [] = 0
myLength2 (_:as) = 1 + myLength2 as
myLength3 :: (Num b) => [a] -> b
mylength3 [] = 0
myLength3 (a:[]) = 1
myLength3 (a:as) = 1 + myLength3 as
myLength4 :: [a] -> Integer
mylength4 [] = 0
myLength4 (a:[]) = 1
myLength4 (a:as) = 1 …Run Code Online (Sandbox Code Playgroud) puppeteer ×5
javascript ×4
c# ×3
node.js ×2
asp.net ×1
dom-events ×1
dynamicquery ×1
haskell ×1
itext ×1
playwright ×1
python ×1
sql ×1