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!fx49.ams4.POSTED!not-for-mail From: Spiros Bousbouras Newsgroups: comp.programming Subject: Re: Advice needed on parsing a youtube page Message-ID: References: In-Reply-To: X-Organisation: Weyland-Yutani Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Lines: 38 X-Complaints-To: http://netreport.virginmedia.com NNTP-Posting-Date: Sat, 27 Feb 2021 16:43:04 UTC Organization: virginmedia.com Date: Sat, 27 Feb 2021 16:43:04 GMT X-Received-Bytes: 2522 Xref: csiph.com comp.programming:12275 On Sat, 27 Feb 2021 14:43:35 GMT Spiros Bousbouras wrote: > I have some code which parses the source of pages for youtube videos and > prints some information. My code has been working fine for months but > recently it choked on https://www.youtube.com/watch?v=w2itwFJCgFQ .After > some investigations I found the part of the page which causes the problem : > there is a single appearance of > > content="\Raffaello D'Andrea\" > > .My code assumed that the closing double quote is escaped so it did not count > it as a closing quote and so parsed incorrectly the rest of the page. I note that if I remove the 2nd backslash , my code can parse the page correctly. Also , there are other appearances of the 2 character sequence \" on the page and for those the " is indeed escaped. So a different way to approach my problem is to come up with an algorithm which decides when \" denotes an escaped double quote and when it doesn't. Ideally , I'm looking for a solution which does not involve writing a full parser for HTML , Javascript , JSON and who knows what else is on such pages. > So I have 2 questions : > > 1. Is the above segment valid according to whatever the relevant specification > is ? > > 2. My code only needs to parse the JSON content of pages and extract the > information I want. Is there a simple algorithm which strips all the non JSON > content of a page ? Or alternatively , is there an algorithm which parses > correctly constructs like the above , perhaps taking into account surrounding > tags ? -- As always, supporting opinionated programming is one of Forth's features, even if it becomes an obstacle to building a critical mass around specific programming strategies. Bruce R. McFarling