简体   繁体   中英

how can i read html source code with line blank using content.match (google app script)

i want to read htmlsource and write price but there are some error

not to read htmlsource

how can i do?

this is what i want to read data

<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.

so i rewrite

but it also doesn't work properly.

  var spanclass = content.match(/<p class="lbl_ItemPriceSingleItem product-price"> <br><\/p>/);

您可能可以使用URLFetchApp类 ,然后使用正则表达式匹配来解析结果。

In JavaScript you can search a string for a match against regular expression using the built-in string.match() function:

var string = "some searchable string for RegEx";
string.match(/some search(.*)/);

The return value of string.match() is an array that contains the matches in the string, with one array item for each match. If no matches are found, it will return null . In the above case, string.match() will return:

[some searchable string for RegEx,  able string for RegEx]

The (.*) in the regular expression finds any character sequence so can be used in between the HTML tags:

var content = '<p class="lbl_ItemPriceSingleItem product-price">USD 425.00\
                                        </p>';  
var spanclass = content.match(/<p class="lbl_ItemPriceSingleItem product-price">(.*)<\/p>/);

In order to get only the text embedded in the <p> tags.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM