Path: csiph.com!news.uzoreto.com!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!81.171.65.13.MISMATCH!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx31.ams4.POSTED!not-for-mail From: Spiros Bousbouras Newsgroups: comp.programming Subject: Re: Advice needed on parsing a youtube page Message-ID: References: <87sg5hp4ra.fsf@bsb.me.uk> <87zgznoihk.fsf@bsb.me.uk> In-Reply-To: <87zgznoihk.fsf@bsb.me.uk> X-Organisation: Weyland-Yutani Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Lines: 158 X-Complaints-To: http://netreport.virginmedia.com NNTP-Posting-Date: Tue, 02 Mar 2021 18:51:40 UTC Organization: virginmedia.com Date: Tue, 02 Mar 2021 18:51:40 GMT X-Received-Bytes: 6586 Xref: csiph.com comp.programming:12293 On Sun, 28 Feb 2021 23:55:19 +0000 Ben Bacarisse wrote: > Spiros Bousbouras writes: [...] > > When I wrote "find the right tags" > > I meant something different. Here is an example from the video I mentioned > > earlier (www.youtube.com/watch?v=w2itwFJCgFQ) : > > [I have added newlines for readability] > > > > === QUOTE > > "videoDetails":{"videoId":"w2itwFJCgFQ", > > "title":"The astounding athletic power of quadcopters | Raffaello D'Andrea", > > "lengthSeconds":"968", > > "keywords":["TEDTalk", > > "TEDTalks", > > "TED Talk", > > "TED Talks", > > "TEDGlobal", > > "\\Raffaello D'Andrea\\", > > "robots", > > "technology"], > > "channelId":"UCAuUUnT6oDeKwE6v1NGQxug", > > "isOwnerViewing":false, > > "shortDescription":"In a robot lab at TEDGlobal, > > SNIP > > https://www.youtube.com/TED", > > "isCrawlable":true, > > SNIP > > "averageRating":4.9200745, > > "allowRatings":true, > > "viewCount":"9755173", > > "author":"TED", > > "isPrivate":false, > > "isUnpluggedCorpus":false, > > "isLiveContent":false}, > > === ENDQUOTE > > > > What I have been calling a tag is a string (like "videoDetails") followed by > > a colon (possibly with intervening whitespace). Lets call those > > JS-tags. > > Ah, I see. So not HTML tags at all. > > > Also > > , I have been referring to the segment above as JSON. I take it it's not JSON > > but Javascript ? Lets call it JSON-like .I'm only interested in the JSON-like > > parts of a page. > > Yes, this is just an object initialiser in JS. The things you call tags > are property names. > > > Some of the JS-tags are followed by a string , some by a [ , some by a { , > > some by a number and some by true or false (not within quotes). > > The property name is followed by an expression that denotes the value of > that property. []s denote array values and {}s denote objects. Ok , it's good to know the correct terminology. > > So I'm > > interested in finding some of those JS-tags and printing the "object" which > > follows. If the JS-tag is followed by a [ or { then I consider as the > > object everything until the matching ] or } respectively whereas if it is > > followed by a string or number or boolean then I want the string or number or > > boolean. > > That's going to work, but only id you start at the "top". Where else would I start ? > > One of the JS-tags I'm interested in is "title" but there are various > > appearances of "title" on the page and the object which follows is not always > > the same. I'm interested in the appearance of "title" which is followed by > > the video title. So for this video > > > > "title":"The astounding athletic power of quadcopters | Raffaello D'Andrea" > > > > Through studying several video pages , the pattern I have noticed is the > > following > > > > "videoDetails":{ > > ...... > > "title":"