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?
Asked
Active
Viewed 292 times
1
-
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 Answers
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
- Escape double quotes in a string (C#)
- Escape double quote character in XML (XML and XPath)

kjhughes
- 106,133
- 27
- 181
- 240