Selenium WebDriver:<option>无法滚动到视图中

时间:2018-09-24 15:51:28

标签: python selenium selenium-webdriver web-scraping

我试图做一个机器人来使用Python和Selenium Webdriver导航网站,但是在尝试访问和更改网站返回的某些数据的result_delimiter时遇到了麻烦。它们使用“逗号”作为默认分隔符,我需要将它们用“换行”分隔

以下是HTML:

<select id="result_delimiter">
                <option value="comma" selected="selected">Comma</option>
                <option value="new_line">New Line</option>
                <option value="space">Space</option>
                <option value="vertical_bar">Vertical Bar</option>
            </select>

错误返回:

Traceback (most recent call last):
  File "C:\Users\...xxx\AsinGrabberTest.py", line 28, in <module>
    select.click()
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <option> could not be scrolled into view

我知道我可以用逗号下载数据,然后在程序中进行更改。当显示结果时,我无法访问文本区域并复制它们。以下是与此文本区域相关的HTML:

<textarea class="asin-holder-big" id="result_list"></textarea>

我要感谢任何解决方案,可以选择“ new_line”选项,也可以复制文本区域中提供的信息。

下面,使用的代码:

import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from pruebaAmazon import copy_link
from selenium.webdriver.support.ui import Select
browser = webdriver.Firefox()
browser.get('http://arkgroup.org/asin-grabber/about/')
currentURL = ('https://www.amazon.com/gp/goldbox/ref=gbps_ftr_s-4_bd57_wht_21023130?ref=nav_cs_gb&gb_f_deals1=dealStates:AVAILABLE%252CWAITLIST%252CWAITLISTFULL%252CEXPIRED%252CSOLDOUT%252CUPCOMING,includedAccessTypes:,sortOrder:BY_SCORE,enforcedCategories:2102313011&pf_rd_p=8cc92576-e249-4c23-a4f8-4720526dbd57&pf_rd_s=slot-4&pf_rd_t=701&pf_rd_i=gb_main&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=AEPDZ9VY9XE3B2FX3W95&ie=UTF8')

def paste_link():
    URL.click()
    URL.send_keys(currentURL)


login = browser.find_element_by_xpath("/html/body/nav/section/ul[1]/li[2]/a").click()
name = browser.find_element_by_xpath("/html/body/div[3]/div[1]/form/input[1]").send_keys('xxx@gmail.com')
password = browser.find_element_by_xpath('/html/body/div[3]/div[1]/form/input[2]').send_keys('xxx')
submit = browser.find_element_by_xpath('/html/body/div[3]/div[1]/form/button').click()
goButton= browser.find_element_by_xpath('/html/body/div[3]/div[2]/div[1]/div[1]/div/a').click()
fetchA = browser.find_element_by_xpath('/html/body/div[2]/div[1]/ul/li[2]/a').click()
URL = browser.find_element_by_xpath('//*[@id="path"]')
#paste_link()
URL.click()
URL.send_keys(currentURL)

fetchButton = browser.find_element_by_xpath('//*[@id="get_asins"]').click()
select = browser.find_element_by_css_selector("html.js.flexbox.flexboxlegacy.canvas.canvastext.webgl.no-touch.geolocation.postmessage.no-websqldatabase.indexeddb.hashchange.history.draganddrop.websockets.rgba.hsla.multiplebgs.backgroundsize.borderimage.borderradius.boxshadow.textshadow.opacity.cssanimations.csscolumns.cssgradients.no-cssreflections.csstransforms.csstransforms3d.csstransitions.fontface.generatedcontent.video.audio.localstorage.sessionstorage.webworkers.no-applicationcache.svg.inlinesvg.smil.svgclippaths body div#Results.reveal-modal.open div.row div.large-6.columns select#result_delimiter option")
select.click()

以及另一个名为“ PruebaAmazon”的.py文件

from selenium import webdriver
import selenium
from selenium.webdriver.support.ui import Select

browser = webdriver.Firefox()           #Sets Firefox as default browser               
browser.get("https://www.amazon.com/")  #Opens amazon page


def copy_link():
    currentURL = browser.current_url
    #print(currentURL)
    return currentURL


login = browser.find_element_by_id('nav-link-accountList').click()
mail = browser.find_element_by_id("ap_email").send_keys('xxx@gmail.com')
continuar = browser.find_element_by_id("continue").click()
password = browser.find_element_by_id("ap_password").send_keys('xxx')
rememberMe = browser.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div/div[2]/div[1]/form/div/div/div/div[3]/div/div/label/div/label/input").click()
signInSubmit = browser.find_element_by_id("signInSubmit").click()
todayDeals = browser.find_element_by_xpath('/html/body/div[1]/header/div/div[2]/div[3]/div[2]/div/a[3]').click();
checkBox = browser.find_element_by_xpath('/html/body/div[1]/div[8]/div/div[2]/div/div[1]/div[1]/div[2]/span[1]/div/label/input').click()

browser.quit()

0 个答案:

没有答案