![](/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.