1

I'm trying to scrape Pinterest using XPath and HTMLAgilityPack, but XPath writes "" (//*(@id="XX") to represent the id attribute value, so in C# the strings are split and I get a syntax error. ("["@id="XX(error)"]") What should I do?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
MJ Nine
  • 11
  • 3
  • You need to provide a sample of the content you want to scrape, as well as the C# source that's not behaving. Otherwise, we're forced to guess at how you're doing it, in which I'd suggest looking at https://stackoverflow.com/questions/14480724/escape-double-quotes-in-a-string – WaitingForGuacamole Feb 24 '21 at 03:40

1 Answers1

1

First, fix your XPath syntax error: Change //*(@id="XX" to //*[@id="XX"].

Then, to represent //*[@id="XX"] as a C# string, use either C# escaping or XPath alternative attribute value delimiters.

C# escaping

Escape the " in C# via \"

"//*[@id=\"XX\"]"

or via verbatim string literal syntax

@"//*[@id=""XX""]"

XPath alternative attribute value delimiters

Use ' as the attribute value delimiter, which both XML and XPath allow:

"//*[@id='XX']"

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240