0

so I have this code on string:

<html class="
no - js ie ie6 lt - ie9 lt - ie8 lt - ie7 search - context en_US " lang="
en - US "> <![endif]--><!--[if IE 7]>         <html class="
no - js ie ie7 lt - ie9 lt - ie8 search - context en_US " lang="
en - US "> <![endif]--><!--[if IE 8]>         <html class="
no - js ie ie8 lt - ie9 search - context en_US " lang="
en - US "> <![endif]--><!--[if IE 9]>         <html class="
no - js ie9 search - context en_US " lang="
en - US "> <![endif]--><!--[if gt IE 9]><!--> <html class="
no - js search - context en_US " lang="
en - US "> <!--<![endif]-->    <head><title>art anime | Tumblr</title><!--[if ie]><meta http-equiv="
X - UA - Compatible " content="
IE = Edge, chrome = 1 "/><![endif]--><meta http-equiv="
Content - Type " content="
text / html;
charset = utf - 8 ">    <meta http-equiv="
x - dns - prefetch - control " content="
off ">    <meta name="
application - name " content="
Tumblr ">    <meta name="
msapplication - TileColor " content="
#3645d">    <meta name= "msapplication-TileImage"
content = "https://assets.tumblr.com/images/msfavicon.png?_v=245323c5cb69e705ea213d9ed60e543a" > < link rel = "shortcut icon"
href = "https://assets.tumblr.com/images/favicons/favicon.ico?_v=8bfa6dd3e1249cd567350c606f8574dc"
type = "image/png" > < meta name = "p:domain_verify"
content = "d06c4fa470a9a6935c9a7b43d57eb7d2" > < link rel = "apple-touch-icon"
sizes = "57x57"
href = "https://assets.tumblr.com/images/apple-touch-icon-57x57.png?_v=81406f92242ce0166328bc17e4473e6e"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "60x60"
href = "https://assets.tumblr.com/images/apple-touch-icon-60x60.png?_v=20e3957f7027b72d5aa60085204ae63c"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "72x72"
href = "https://assets.tumblr.com/images/apple-touch-icon-72x72.png?_v=8df24181ba31066d8710f67c9a287241"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "76x76"
href = "https://assets.tumblr.com/images/apple-touch-icon-76x76.png?_v=455617cae13eff40acffac5e489bde50"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "120x120"
href = "https://assets.tumblr.com/images/apple-touch-icon-120x120.png?_v=5604f95b165810101ea055f2cb5206b9"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "128x128"
href = "https://assets.tumblr.com/images/apple-touch-icon-128x128.png?_v=fd39307925fa7f1ada28b08d67e93da1"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "144x144"
href = "https://assets.tumblr.com/images/apple-touch-icon-144x144.png?_v=dfd5b392d423c5f0278d9f498abda2fa"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "152x152"
href = "https://assets.tumblr.com/images/apple-touch-icon-152x152.png?_v=73c2019bf6a75f7e476e01ba136cebec"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "180x180"
href = "https://assets.tumblr.com/images/apple-touch-icon-180x180.png?_v=00127c0342d97d5f36cfd8aa6439ca10"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "195x195"
href = "https://assets.tumblr.com/images/apple-touch-icon-195x194.png?_v=0"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "196x196"
href = "https://assets.tumblr.com/images/apple-touch-icon-196x196.png?_v=bb4b7eef0ef8e28101acdf2f0c265cc7"
type = "image/png" > < link rel = "apple-touch-icon"
sizes = "228x228"
href = "https://assets.tumblr.com/images/apple-touch-icon-228x228.png?_v=0c7874da12e347c2bdf95e5baa3f396a"
type = "image/png" > < link rel = "canonical"
href = "https://www.tumblr.com/search/art%20anime/recent" > < meta name = "robots"
id = "robots"
content = "noodp,noydir" > < meta name = "description"
id = "description"
content = "Tumblr is a place to express yourself, discover yourself, and bond over the stuff you love. It&#039;s where your interests connect you with your people." > < meta name = "keywords"
id = "keywords"
content = "tumblelog, blog, tumblog, tumbler, tumblr, tlog, microblog" > < meta name = "viewport"
id = "viewport"
content = "width=960" > < meta name = "tumblr-form-key"
id = "tumblr_form_key"
content = "!1231553203788|mOZjoWSzPU6eNRkpuhEtzoBJmdA" > < meta name = "tumblr-gpop"
id = "tumblr_gpop"
content = "Tumblr" > < meta name = "og:title"
id = "og_title"
content = "art anime | Tumblr" > < meta name = "og:image"
id = "og_image"
content = "https://66.media.tumblr.com/06afadc2cafb6945065a4b10d61f3b45/tumblr_poqjiuUUGO1tvlw71o1_r1_500.jpg" > < script type = "application/ld+json" >

I want to get content="https://66.media.tumblr.com ... etc link from this string and for you know the string is updating every hour

I try this way not working I result -1 and 0 on google script ( java script ) cods

function urll() { var response =
  UrlFetchApp.fetch("https://www.tumblr.com/search/art+anime/recent");
  var str = response.getContentText(); var m=str.search('is=“og_image”
  content=“(^”*)'); Logger.log(m); 
}
4
  • This is the exact string you want to parse? Commented Mar 21, 2019 at 22:10
  • yeah , how i exact ? Commented Mar 21, 2019 at 22:13
  • Well this 'string' doesn't look like a plain string - more like html - and not really usable as a string with all those " characters in it. Where do you get it from? Commented Mar 21, 2019 at 22:36
  • how you storing this sting content, it gives error when you put this in any variable, Commented Mar 22, 2019 at 6:25

2 Answers 2

2

Use jquery to grab it. Per your example above, there is a unique id of og_image, so use that to get the meta element, then narrow it down to the content attribute.

$("meta #og_image").attr("content");

Assuming you already have that whole mess in a single variable myString:

var regex = /66\.[^"]*/;
var myLink = myString.match(regex);

myLink[0] will be the url.

To make this answer a bit more useful for other similar situations rather than just this niche case, if you're trying to pull a link out of a long string like this that contains many, you can use:

var regex = /http[^"]*/g;
var links = myString.match(regex);

That will give you an array of all the links.

links[links.length-1];

Will be the last one, which is what you want in this case.

Sign up to request clarification or add additional context in comments.

2 Comments

but the problem this is cod is "string"
Added the javascript regex to parse out just the url from this "string" if you already have it in a variable.
0

You can use regular expression like ‘is=“og_image” content=“(^”*)’ it will take every content url If you need only last one, you can add the id parameter validation also

3 Comments

I don't know how add parameter validation, can you give example
I’ve updated my code. If you’ll need more details I can make the whole code sample later
jQuery sample will work - you just need to initialize the object with your string. Same way you use to create new html elements to be added to the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.