Home > Net >  Webscraping customer review - Invalid selector error using XPath
Webscraping customer review - Invalid selector error using XPath

Time:11-30

I am trying to extract userid, rating and review from the following site using selenium and it is showing "Invalid selector error". I think, the Xpath I have tried to define to get the review text is the reason for error. But I am unable to resolve the issue. The site link is as below:

Webscraping error

Also, The xpath that I tried to trace is from following HTML enter image description here

CodePudding user response:

You are seeing the classic error of...

InvalidSelectorException

as find_elements_by_xpath('//*[@id="' x '"]]/div[3]/p[2]/text()')[0] would select the attributes, instead you need to pass an expression that selects elements.

You need to change as:

user_message = self.driver.find_elements_by_xpath('//*[@id="'   x  '"]]/div[3]/p[2]')[0]

References

You can find a couple of relevant detailed discussions in:

  • Related