why <div class=\"gn_topmenulist\"> ? what is the \

405 Views Asked by At

The background is that I use the scrapy to crawl weibo.com,but I find the the tags in html crawled includes '\" looks like the title: ,that makes I can not use xpath to get the information, so why the \ appears.

enter image description here

2

There are 2 best solutions below

2
On BEST ANSWER

In plain English: String literals can be enclosed in matching single quotes (') or double quotes ("). They can also be enclosed in matching groups of three single or double quotes (these are generally referred to as triple-quoted strings). The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

enter image description here

Python Reference Manual:String literals

2
On

The backslash is used to escape the quotation marks, because otherwise the first quotation mark would end the string, hence the end of the output, so the rest might not appear, or would break if you're using the output in a program.