Scrapy CSS selector for HTML element with class containing non alphanumeric char

Viewed 1246

I am using Scrapy to crawl a site. I am trying to select an element in the response.

My response object contains HTML that looks like this:

<html>
    <head><title>Title goes here</title</head>
    <body>
         <!-- lots of stuff I am not interested in -->
         <select class="Gy(t)">
             <!-- elements -->
         </select>
         <!-- lost more stuff of no interest to me -->
    </body>
</html>

My code:

def parse(self, response):
    # ....
    print (response.selector.css('select.Gy(t)'))

I got the folowing exception thrown when I run my code:

"Expected selector, got %s" % (peek,))
File "<string>", line None
cssselect.parser.SelectorSyntaxError: Expected selector, got <DELIM '(' at 9>

How can I use a selector (preferably a CSS selector) to select this HTML element?

1 Answers

you can escape the parenthesis on the css selector, so try:

response.css('select.Gy\(t\)')
Related