我需要在截取屏幕截图或生成 PDF 之前删除标签。
有什么办法可以导致这个吗?
我尝试添加page.addScriptTag(options)和page.addStyleTag(options)。
我收到如下错误:
Error when rendering page: TypeError: page.addStyleTag is not a function
Run Code Online (Sandbox Code Playgroud) 我已删除的代码几件找出它在哪里,它的背后是什么在div" wrapper".还有更多div设计用于显示其他内容,但它们没有类名" changeimage".
<div id="wrapper">
<div id="content">
<div align="center" id="imagesbar">
<img class="changeimage" src="image1.jpg"/>
</div>
<div align="center" id="imagestext">
<h1 class="headertext"><strong>What we do.</strong></h1>
<br /><p class="circle" >Mowing</p>
<p class="circle">Lawn Care</p>
<p class="circle">Weed Removing</p>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和JavaScript:
var images = ['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg', 'image5.jpg', 'image6.jpg', 'image7.jpg'];
var interval = setInterval(changeImage, 4000);
var index = 0;
function changeImage(){
//alert("changing image")
document.getElementsByClassName("changeimage").src = images[index];
index++;
}
Run Code Online (Sandbox Code Playgroud)
在行中" document.getElementsByClassName("changeimage")"是具有错误的代码的行.似乎我正在使用的浏览器(这是Chrome)找不到类名" changeimage".我想将类名为" " src的HTML条目上的标记更改为JavaScript中字符串数组中的不同位置,具体取决于索引.imgchangeimage
我想从站点(例如“example.com”)获取 HTML 源代码。
我尝试了以下方法:
import urllib2
response = urllib2.urlopen("https://example.com")
page_source = response.read()
Run Code Online (Sandbox Code Playgroud)
它说:
'没有名为 urllib2 的模块'
我怎样才能防止这个错误?
我正在使用 CucumberJS 和 Puppeteer。我很难从<h1>标签中提取文本。
ember .hbs 代码是:
<div class="grid__cell" data-test-foobar4="true">
<h1 class="ao-headline u-font--light" data-test-foobar3="true">{{pageTitle}}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
data-因为 EmberJS 使用动态 id,所以我为我的选择器使用了 HTML标签。
// Read page table title
async verifyTestTileForList() {
const textContent = await this.page.evaluate(() => document.body.querySelector('[data-test-foobar3="true"]').textContent);
console.log('Page title = ' + textContent);
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到:
错误:评估失败:类型错误:无法读取 null 的属性“textContent”
这对我来说没有意义。我查看了 HTML,我看到:
<h1 data-test-foobar3="true" class="ao-headline u-font--light">Imports</h1>
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我想将鼠标悬停在某个元素上,比如说document.getElementById("abc")并找到它的悬停计算样式。
我应该如何使用 Puppeteer 在 Node.js 中做到这一点?
我有一个数据框,其中包含一列连续但不相邻的数字和缺失值。
我想使用该fillna函数用前一个非缺失行的递增值填充缺失值。
这是一个简化的表格:
index my_counter
0 1
1 2
2 NaN
3 3
4 NaN
5 NaN
6 8
Run Code Online (Sandbox Code Playgroud)
我想这样填写my_counter:
index my_counter
0 1
1 2
2 2.1
3 3
4 3.1
5 3.2
6 8
Run Code Online (Sandbox Code Playgroud)
我怎样才能完成这个任务?
How do I add text summary to Tensorboard when using Keras?
I have setup a Tensorboard callback, but I am lost on how to add a text summary.
For example, I would like to add a text summary of different parameters used in the run into the Tensorboard so that for documentation and not lost when I revisit the run log.
One option seems to be to include all the parameter details to the logfile dir name, but that looks …
我正在使用反应式文本框,我需要一些自定义验证。
输入框不能有以空格开头的字符。
我正在使用所需的验证器使其成为强制性的,但如果我输入一个空格,它仍然认为它有效(我不想要)。
我怎样才能解决这个问题?
我需要Puppeteer暂停并等待和的用户输入,username然后password才能继续。这是一个nodejs8.12.0应用程序。
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://www.myweb.com/login/');
//code to wait for user to enter username and password, and click `login`
const first_page = await page.content();
//do something
await browser.close();
)}();
Run Code Online (Sandbox Code Playgroud)
基本上,程序会暂停并等待,直到用户单击login按钮。有可能这样做Puppeteer吗?或者我还能做什么?
我需要使用 XPath 选择页面上的所有链接,然后我的 Puppeteer 应用程序才能单击并执行一些操作。我发现该方法(下面的代码)有时会卡住,我的爬虫会暂停。是否有更好/不同的方式从 XPath 获取所有链接?或者我的代码中是否存在不正确的内容并且可能会暂停我的应用程序的进度?
try {
links = await this.getLinksFromXPathSelector(state);
} catch (e) {
console.log("error getting links");
return {...state, error: e};
}
Run Code Online (Sandbox Code Playgroud)
其中调用:
async getLinksFromXPathSelector(state) {
const newPage = state.page
// console.log('links selector');
const links = await newPage.evaluate((mySelector) => {
let results = [];
let query = document.evaluate(mySelector,
document,
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i=0, length=query.snapshotLength; i<length; ++i) {
results.push(query.snapshotItem(i).href);
}
return results;
}, state.linksSelector);
return links;
}
Run Code Online (Sandbox Code Playgroud)
XPath 位于state.linksSelector.