macosx上的python scrapy shell :: selenium.webdriver.common.action_chains.ActionChains at 0x1060d8bd0

时间:2017-02-27 03:21:55

标签: python shell selenium scrapy

我正试图在我的mac上用python编写一个刮刀。它的shell给了我以下内容:

In [159]: print AGM_LINK
<a id="agm" class="agm" href="#" onclick="loadEvents('agm')">AGM</a>

In [160]: actions.move_to_element(AGM_LINK)
Out[160]: <selenium.webdriver.common.action_chains.ActionChains at 0x1060d8bd0>

In [161]: actions.click()
Out[161]: <selenium.webdriver.common.action_chains.ActionChains at 0x1060d8bd0>

In [162]: actions.perform()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-162-52a1ddc57036> in <module>()
----> 1 actions.perform()

/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/action_chains.pyc in perform(self)
     72         """
     73         for action in self._actions:
---> 74             action()
     75 
     76     def click(self, on_element=None):

/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/action_chains.pyc in <lambda>()
    223         """
    224         self._actions.append(lambda: self._driver.execute(
--> 225             Command.MOVE_TO, {'element': to_element.id}))
    226         return self
    227 

AttributeError: 'unicode' object has no attribute 'id'

我正在抓取的链接是http://lankabd.com/portal/corporateEventsCalendarIframe.html

我已经尝试过这种方式的快捷方式

ActionChain(self.driver).move_to_element(AGM_LINK).click().perform()

我似乎无法在这里找到问题。

之前我尝试了以下内容(我在那里尝试了不同的东西):

# Helps from :
# -----------
#     ActionChains - http://selenium-python.readthedocs.io/api.html
#     SwitchTo() - http://stackoverflow.com/a/19060830/2378780
import scrapy
from selenium import WebDriver
from selenium.webdriver.common.action_chains import ActionChains

class CompSpider(scrapy.Spider):
    name            = "CompSpider"
    allowed_domain  = ["lankabd.com"]
    start_urls      = ["http://lankabd.com/"]

    def __init__(self):
        self.driver = WebDriver.PhantomJS()

    def parse(self, response):
        self.driver.get("http://lankabd.com/portal/corporateEventsCalendarIframe.html")
        # link = response.selecor.xpath("//a[@onclick=\"loadEvents('agm')\"]")
        # yield Request(response.urljoin(link),  headers=headers, callback=self.second)

        LINK_SET   = self.driver.find_element_by_css_selector(".links")
        EVENT_LINK = self.driver.find_element_by_css_selector(".links a#agm")
        ActionChain(self.driver).move_to_element(LINK_SET).click(EVENT_LINK).perform()

        yield response

        self.driver.close()

作为一个新手,可能是我在尝试另一个方向!任何帮助都非常感谢。

0 个答案:

没有答案