我正在使用Scrapy抓取网站。我试图在响应中选择一个元素。
我的响应对象包含如下所示的HTML:
<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>
def parse(self, response):
# ....
print (response.selector.css('select.Gy(t)'))
我运行代码时抛出了以下异常:
"Expected selector, got %s" % (peek,))
File "<string>", line None
cssselect.parser.SelectorSyntaxError: Expected selector, got <DELIM '(' at 9>
如何使用选择器(最好是CSS选择器)来选择此HTML元素?
答案 0 :(得分:4)
你可以转义css选择器上的括号,所以试试:
response.css('select.Gy\(t\)')