Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.programming Subject: Re: Advice needed on parsing a youtube page Date: Sun, 28 Feb 2021 23:55:19 +0000 Organization: A noiseless patient Spider Lines: 176 Message-ID: <87zgznoihk.fsf@bsb.me.uk> References: <87sg5hp4ra.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="b632a0d5348845cc287f5c1e43d1bb39"; logging-data="25874"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aTem9cevEN+ibEieROX1O9umTbW8/zL4=" Cancel-Lock: sha1:0S2rDWDLXq4bgh4YvyFf3KpbWHA= sha1:qG0raijdu5FUOckbXhGp/LpLVZY= X-BSB-Auth: 1.d988a2b3704e15b61eb3.20210228235519GMT.87zgznoihk.fsf@bsb.me.uk Xref: csiph.com comp.programming:12284 Spiros Bousbouras writes: > On Sat, 27 Feb 2021 21:42:01 +0000 > Ben Bacarisse wrote: >> Spiros Bousbouras writes: >> >> > Otherwise , in your last 2 paragraphs you seem to only restate my question. >> > In order to find the right tags , I need to find the JSON strings ; and in >> > order to find those I need to locate correctly where each string (whether >> > it is part of JSON or part of an HTML tag) starts and ends ; and in order >> > to do that I need to know whether a string is part of JSON or part of an >> > HTML tag so that I can apply the correct rule to locate the closing double >> > quote. >> >> I know it's annoying, but I have to correct some of your terms (or at >> least clarify them) so we can all be on the same page. An HTML tag >> looks like this:

. That's an opening tag. You can also have closing >> tags like

. Some tags denote elements (like
) all by >> themselves, but often an element is constructed form the opening tag, >> the content and the (sometimes implicit) closing tag. > > No , it's not annoying and it's necessary. 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. > 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". > 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":"