2017-12-31 105 views
0

사용자 입력이있는 경우 Instagram 페이지를 통해 탭을 만들려고합니다. 나는 그 페이지에 갈 수있다. 페이지가로드되고 클래스가 발견되면 코드가 손상됩니다. 나는이 오류가 계속WebElement에는 속성이 없습니다. w3c

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가 페이지 아래로 여러 번 탭하는 가장 좋은 방법 인 것처럼 보이지만 누군가가 더 나은 방법을 사용하고 있다면 시도해 볼 수 있습니다.

답변

1

ActionChainsWebDriver을 받아야하지만, 대신

actions = ActionChains(driver) 
WebElement을 보내는
관련 문제