![](/img/trans.png)
[英]Google drive app: How can i get my HTML file to read a varitable defined in code.gs?
[英]how can i read html source code with line blank using content.match (google app script)
我想阅读htmlsource和写价格,但有一些错误
不读htmlsource
我能怎么做?
<p class="lbl_ItemPriceSingleItem product-price">USD 425.00
</p>
var spanclass = content.match(/<p class="lbl_ItemPriceSingleItem product-price"><\/p>/);
->
var spanclass = content.match(/<p class="lbl_ItemPriceSingleItem product-price"> <br><\/p>/);
p>/p>is far away. So I think can't read html properly.
所以我重写
但它也无法正常工作。
var spanclass = content.match(/<p class="lbl_ItemPriceSingleItem product-price"> <br><\/p>/);
您可能可以使用URLFetchApp类 ,然后使用正则表达式匹配来解析结果。
在JavaScript中,您可以使用内置的string.match()
函数在字符串中搜索与正则表达式的匹配项:
var string = "some searchable string for RegEx";
string.match(/some search(.*)/);
string.match()
的返回值是一个数组,其中包含字符串中的匹配项,每个匹配项都有一个数组项。 如果没有找到匹配项,它将返回null
。 在上述情况下, string.match()
将返回:
[some searchable string for RegEx, able string for RegEx]
正则表达式中的(.*)
可以找到任何字符序列,因此可以在HTML标记之间使用:
var content = '<p class="lbl_ItemPriceSingleItem product-price">USD 425.00\
</p>';
var spanclass = content.match(/<p class="lbl_ItemPriceSingleItem product-price">(.*)<\/p>/);
为了只获取嵌入在<p>
标记中的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.