使用硒列出Instagram上所有帖子的喜欢

时间:2019-03-15 11:48:00

标签: python selenium

我有此代码,该代码应在instagram帖子上的喜欢列表中列出,但运行它会向我显示错误:

   selenium.common.exceptions.WebDriverException: Message: unknown
     error: Element <a class="zV_Nj"
    href="/p/BuE82VfHRa6/liked_by/">...</a> is not clickable at point
    (648, 621). Other element would receive the click: <div class="       
    Igw0E   rBNOH     pmxbr     YBx95   ybXk5    _4EzTm                   
    " style="width: 903px;">...</div>

这是代码:

from selenium import webdriver
driver = webdriver.Chrome("C:/chromedriver.exe")
driver.get('https://www.instagram.com/p/Bu7TXRFAK5u/')

userid_element = driver.find_elements_by_xpath('//*[@id="react-root"]/section/main/div/div/article/div[2]/section[2]/div/div/a')[0].click()
time.sleep(2)

users = []
height = driver.find_element_by_xpath("/html/body/div[3]/div/div[2]/div/div").value_of_css_property("padding-top")
match = False
while match==False:
lastHeight = height
# step 1
elements = driver.find_elements_by_xpath("//*[@id]/div/a")
# step 2
for element in elements:
    if element.get_attribute('title') not in users:
        users.append(element.get_attribute('title'))
# step 3
driver.execute_script("return arguments[0].scrollIntoView();", elements[-1])
time.sleep(1)
# step 4
height = driver.find_element_by_xpath("/html/body/div[3]/div/div[2]/div/div").value_of_css_property("padding-top")
if lastHeight==height:
    match = True
print(users)
print(len(users))
driver.quit()

这是因为网站加载不正确吗?

0 个答案:

没有答案