I'm trying to scrape contents from this page on my linux machine. I want to display all the list of wines by clicking the show more
button [around 600] until no show more buttons appear. I'm using selenium
and PhantomJS
for handling javascripts. I'm using time.sleep()
show that once i click the show more
button, it sleeps for some short time until another appears. The problem i'm facing is, initially the program clicks the show more button quickly but once it reaches around 100-150 clicks, the time taken to detect the show more
button increases at an alarming rate, taking too much time. Below is the code that detects the show more
button and clicks it.
def parse(self,response):
sel = Selector(self.driver.get(response.url))
self.driver.get(response.url)
click = self.driver.find_elements_by_xpath("//*[@id='btn-more-wines']")
try:
while click:
click[0].click()
time.sleep(2)
except Exception:
print 'no clicks'