Path: csiph.com!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx46.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> In-Reply-To: <87sg5hp4ra.fsf@bsb.me.uk> X-Organisation: Weyland-Yutani Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Lines: 134 X-Complaints-To: http://netreport.virginmedia.com NNTP-Posting-Date: Sun, 28 Feb 2021 21:02:52 UTC Organization: virginmedia.com Date: Sun, 28 Feb 2021 21:02:52 GMT X-Received-Bytes: 7026 Xref: csiph.com comp.programming:12283 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 .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. 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). 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. 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":"