我需要匹配所有这些开始标记:
<p>
<a href="foo">
Run Code Online (Sandbox Code Playgroud)
但不是这些:
<br />
<hr class="foo" />
Run Code Online (Sandbox Code Playgroud)
我想出了这个,并希望确保我做对了.我只抓住了a-z.
<([a-z]+) *[^/]*?>
Run Code Online (Sandbox Code Playgroud)
我相信它说:
/,然后我有这个权利吗?更重要的是,你怎么看?
我想使用Google Spreadsheets和Google Apps脚本创建一个刮刀.我知道这是可能的,我已经看过一些关于它的教程和线程.
主要想法是使用:
var html = UrlFetchApp.fetch('http://en.wikipedia.org/wiki/Document_Object_Model').getContentText();
var doc = XmlService.parse(html);
Run Code Online (Sandbox Code Playgroud)
然后开始使用这些元素.但是,方法
XmlService.parse()
Run Code Online (Sandbox Code Playgroud)
对某些页面不起作用.例如,如果我尝试:
function test(){
var html = UrlFetchApp.fetch("https://www.nespresso.com/br/pt/product/maquina-de-cafe-espresso-pixie-clips-preto-lima-neon-c60-220v").getContentText();
var parse = XmlService.parse(html);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error on line 225: The entity name must immediately follow the '&' in the entity reference. (line 3, file "")
Run Code Online (Sandbox Code Playgroud)
我试图用来string.replace()消除显然导致错误的字符,但它不起作用.出现所有其他错误.以下代码为例:
function test(){
var html = UrlFetchApp.fetch("https://www.nespresso.com/br/pt/product/maquina-de-cafe-espresso-pixie-clips-preto-lima-neon-c60-220v").getContentText();
var regExp = new RegExp("&", "gi");
html = html.replace(regExp,"");
var parse = XmlService.parse(html);
}
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
Error on line 358: The content of elements must …Run Code Online (Sandbox Code Playgroud) javascript parsing html-parsing google-sheets google-apps-script
我正在尝试从 HTML 页面中提取字符串变量中的一些数据。我知道Google Apps脚本代码是在服务器端执行的,并且document对象没有定义。
是否有其他简单的方法可以使用 CSS 选择器(如 ) 来提取数据document.querySelector?