How To Scrape All Steam Id, Review Content, Profile_url From Reviews Of A Game In Steam Into Excel File Using Python?
#The error is either it prints only first 11 reviews (when while n<500 is used) or does not print at all(when while True: is used). Requirement is to save all Steam id, review c
Solution 1:
Here's how to infinitely scroll down or until 500 elements in your case.
while True:
cards = driver.find_elements_by_class_name('apphub_Card')
if(len(cards)>=500):
break
last_position = driver.execute_script("return window.pageYOffset;")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(1)
curr_position = driver.execute_script("return window.pageYOffset;")
if(last_position==curr_position):
break
for card in cards[:500]:
profile_url = card.find_element_by_xpath('.//div[@class="apphub_friend_block"]/div/a[2]').get_attribute('href')
steam_id = profile_url.split('/')[-2]
date_posted = card.find_element_by_xpath('.//div[@class="apphub_CardTextContent"]/div').text
review_content = card.find_element_by_xpath('.//div[@class="apphub_CardTextContent"]').text.replace(date_posted,'').strip()
review = (steam_id, profile_url, review_content)
reviews.append(review)
Post a Comment for "How To Scrape All Steam Id, Review Content, Profile_url From Reviews Of A Game In Steam Into Excel File Using Python?"