【发布时间】:2019-02-20 17:38:02
【问题描述】:
我在亚马逊上抓取页面时遇到问题。
我尝试过使用:
- 执行 JS 脚本
- 动作链
- 显式等待
似乎没有任何效果。一切都会引发一个异常或错误。
基础脚本
ff = create_webdriver_instance()
ff.get('https://www.amazon.ca/gp/goldbox/ref=gbps_ftr_s-3_4bc8_dct_10-?gb_f_c2xvdC0z=sortOrder:BY_SCORE,discountRanges:10-25%252C25-50%252C50-70%252C70-&pf_rd_p=f5836aee-0969-4c39-9720-4f0cacf64bc8&pf_rd_s=slot-3&pf_rd_t=701&pf_rd_i=gb_main&pf_rd_m=A3DWYIK6Y9EEQB&pf_rd_r=CQ7KBNXT36G95190QJB1&ie=UTF8')
next_button = ff.find_element_by_xpath('(//li/a[contains(text(), "Next")])[1]')
尝试 #1:执行 JS
脚本
ff.execute_script('arguments[0].scrollIntoView()', next_button)
错误
Element could not be scrolled into view
尝试 #2:动作链
脚本
actions = ActionChains(ff)
actions.move_to_element(next_button)
actions.click(next_button)
actions.perform()
错误
TypeError: rect is undefined
尝试 #3:显式等待
next_button = WebDriverWait(ff, 60).until(
EC.visibility_of_element_located((By.XPATH, '(//li/a[contains(text(), "Next")])[1]'))
)
我也尝试过使用element_to_be_clickable。这两个最终都会超时。
【问题讨论】:
标签: python selenium web-scraping web-crawler screen-scraping