gpt4 book ai didi

python - WebElement 没有属性 w3c

转载 作者:太空宇宙 更新时间:2023-11-04 09:50:18 27 4
gpt4 key购买 nike

我正在尝试在给定用户输入的情况下浏览 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 键的最佳方式,但如果有人有更好的方法,我愿意尝试。

最佳答案

ActionChains 应该接收 WebDriver,但您发送的是 WebElement

actions = ActionChains(driver)

关于python - WebElement 没有属性 w3c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48046342/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com