【问题标题】:WebElement has no Attribute w3cWebElement 没有属性 w3c
【发布时间】:2017-12-31 23:50:15
【问题描述】:

在给定用户输入的情况下,我正在尝试通过 Instagram 页面切换。我能够访问该页面。页面加载,然后找到类,然后代码中断。这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys 
from  bs4 import BeautifulSoup
import urllib.request, urllib.parse, urllib.error
import time

def get_posts(tag, user_count):

    '''Getting html of page to be scrape for
    hrefs that will get me the user names'''

    print("getting page")
    url = "https://www.instagram.com/explore/tags/" + tag + "/"
    try:
        driver = webdriver.Chrome()
        driver.get(url)
        print("successfully requested site")
    except:
        print("Unable to reach site")
        quit()

    browser = driver.find_element_by_class_name('_si7dy')
    actions = ActionChains(browser)
    for i in range(user_count):
        actions = actions.send_keys(Keys.TAB)
        time.sleep(0.5)
    actions.perform()



    soup = BeautifulSoup(driver.page_source, 'lxml')

    try:
        posts = soup.find_all("div", class_ = ["_mck9w","_gvoze","_f2mse"])
    except:
        print("No links found")
        quit()

    print("Length of posts: ",(len(posts)))

    print(len(posts))
    print(type(posts))
    print("All Done")
    driver.close()
    return posts

我不断收到此错误:

packages\selenium\webdriver\common\action_chains.py", line 69, in __init__
        if self._driver.w3c:
    AttributeError: 'WebElement' object has no attribute 'w3c'

我已经四处搜索,但没有找到关于 w3c 的任何信息。我以前从来没有翻页过,所以我使用的是这里找到的答案:Send multiple tab key presses with selenium

ActionChains 似乎是在页面中多次使用 tab 的最佳方式,但如果有人有更好的方法,我愿意尝试。

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver action


    【解决方案1】:

    ActionChains 应该会收到 WebDriver,但您却发送的是 WebElement

    actions = ActionChains(driver)
    

    【讨论】:

      猜你喜欢
      • 2015-03-05
      • 2016-07-28
      • 2020-03-09
      • 1970-01-01
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 2013-04-27
      相关资源
      最近更新 更多