Webソースにデータが存在し、selenumを使用してデータを解析できない解決方法.
2010 ワード
def scroll_to_bottom(driver): #
js = "return action=document.body.scrollHeight" #
# 0
height = 0
#
new_height = driver.execute_script(js)
while height < new_height: # ,
#
for i in range(height, new_height, 200):
driver.execute_script('window.scrollTo(0, {})'.format(i))
time.sleep(0.5)
height = new_height # , 。
# time.sleep(random.random())
new_height = driver.execute_script(js) #
def index_page(page):
''' :param page: '''
try:
print(' ', page, ' ')
url = 'https://search.suning.com/%s/'%(quote(KEYWORD))
url = 'https://search.suning.com/%s/&iy=0&isNoResult=0&cp=%d'%(quote(KEYWORD), page)
browser.get(url) #
# : ,
# wait.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#mainsrp-pager li.item.active > span'), str(page)))
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#nextPage'))) # ,
scroll_to_bottom(browser) # ,
time.sleep(3)
get_products(page) #
except TimeoutException:
index_page(page)