I'm attempting to scrape dates from Yelp. I noticed there is only one difference in the web elements for the dates of reviews, it is a number where I have inputed the num variable. I was hoping to assign the number to the num variable, then increase the value of variable until there is nothing else to grab. I'm still a python noob and was hoping to get an old pros help with this?
Code is down below, my thought process was that I will add the element to the array then increase it before the loop so that it doesn't match right away and break the loop.
Here is the webpage https://www.yelp.com/biz/gordon-ramsay-hells-kitchen-las-vegas-3?osq=Restaurants&sort_by=date_desc
And for clarification it is the review dates I'm interested it.
def date_harvesting(self): self.num = [] num = 1 i = 0 tester = self.driver.find_element_by_xpath('/html/body/div[2]/div[3]/yelp-react-root/div/div[3]/div/div/div[2]/div/div[1]/div[2]/section[2]/div[2]/div/ul/li[' + str(num) + ']/div/div[2]/div/div[2]/span') self.num.append(tester.text) num += 1 while i < num: if self.num[i] != tester.text: self.num.append(tester.text) i += 1 num += 1 else: i += 1 print(tester) print(self.num)
https://stackoverflow.com/questions/67362583/iterating-thru-a-web-element May 03, 2021 at 09:35AM
没有评论:
发表评论