表数据未在python硒中检索

时间:2019-03-08 04:53:52

标签: python-3.x selenium-webdriver

我正在学习硒。我试图从vimeo收集所有图像链接。它成功登录,并到达我要检索的数据部分。但是它只检索第一个71链接。我不明白我要去哪里。我也试图等待页面加载。但是仍然只有3个链接。我也尝试滚动但没有任何改变。我该怎么办?

<table class="sc-jVODtj hxSYTz">
<tbody>

    <tr class="video_manager__table_item" draggable="true">
        <td class="video_manager__table_cell video_manager__checkbox">
            <div class="_16rrx">
                <div class="sc-jhAzac jfCOJP">
                    <label class="_1jZ-U UkGA_ sc-dVhcbM gECuNC sc-jWBwVP iqHKee" format="dark"><span><input type="checkbox" class="sc-fMiknA gpqhYy" value="on"><span class="sc-fBuWsC dGFkNH"><div class="sc-fAjcbJ kvdeNU"></div></span><span class="sc-eqIVtm jIEUZS"></span></span>
                    </label>
                </div>
                <div class="">
                    <!-- react-empty: 578 -->
                    <!-- react-empty: 579 -->
                </div>
            </div>
        </td>
        <td class="video_manager__table_cell video_manager__table_cell--thumb">
            <div class="table_cell__thumb-wrapper" data-fatal-attraction="container:video_manager_list|component:video|keyword:thumbnail">
                <a target="_blank" href="/321669493/settings">
                    <div class="_1tULj">
                        <div class="_3XET0" style="background-image: url(&quot;https://i.vimeocdn.com/video/764433135_236x133.jpg&quot;);"></div>
                    </div>
                </a>
            </div>
        </td>

    </tr>
    <tr class="video_manager__table_item" draggable="true">
        <td class="video_manager__table_cell video_manager__checkbox">
            <div class="_16rrx">
                <div class="sc-jhAzac jfCOJP">
                    <label class="_1jZ-U UkGA_ sc-dVhcbM gECuNC sc-jWBwVP iqHKee" format="dark"><span><input type="checkbox" class="sc-fMiknA gpqhYy" value="on"><span class="sc-fBuWsC dGFkNH"><div class="sc-fAjcbJ kvdeNU"></div></span><span class="sc-eqIVtm jIEUZS"></span></span>
                    </label>
                </div>
                <div class="">
                    <!-- react-empty: 602 -->
                    <!-- react-empty: 603 -->
                </div>
            </div>
        </td>
        <td class="video_manager__table_cell video_manager__table_cell--thumb">
            <div class="table_cell__thumb-wrapper" data-fatal-attraction="container:video_manager_list|component:video|keyword:thumbnail">
                <a target="_blank" href="/319499775/settings">
                    <div class="_1tULj">
                        <div class="_3XET0" style="background-image: url(&quot;https://i.vimeocdn.com/video/762092910_236x133.jpg&quot;);"></div>
                    </div>
                </a>
            </div>
        </td>

    </tr>
    <tr class="video_manager__table_item" draggable="true">
        <td class="video_manager__table_cell video_manager__checkbox">
            <div class="_16rrx">
                <div class="sc-jhAzac jfCOJP">
                    <label class="_1jZ-U UkGA_ sc-dVhcbM gECuNC sc-jWBwVP iqHKee" format="dark"><span><input type="checkbox" class="sc-fMiknA gpqhYy" value="on"><span class="sc-fBuWsC dGFkNH"><div class="sc-fAjcbJ kvdeNU"></div></span><span class="sc-eqIVtm jIEUZS"></span></span>
                    </label>
                </div>
                <div class="">
                    <!-- react-empty: 626 -->
                    <!-- react-empty: 627 -->
                </div>
            </div>
        </td>
        <td class="video_manager__table_cell video_manager__table_cell--thumb">
            <div class="table_cell__thumb-wrapper" data-fatal-attraction="container:video_manager_list|component:video|keyword:thumbnail">
                <a target="_blank" href="/319303335/settings">
                    <div class="_1tULj">
                        <div class="_3XET0" style="background-image: url(&quot;https://i.vimeocdn.com/video/761962359_236x133.jpg&quot;);"></div>
                    </div>
                </a>
            </div>
        </td>

    </tr>
   </tbody>
  </table>

代码

 from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, \
WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time


driver = webdriver.Chrome(executable_path='/Users/lmuser/chromedriver')
driver.get ("https://vimeo.com/log_in")
driver.find_element_by_id("signup_email").send_keys("**")
driver.find_element_by_id("login_password").send_keys("**")
login = driver.find_element_by_xpath("//input[@value='Log in with 
email']")
login.click()
all_video = driver.find_element_by_xpath("//a[@href='/manage/videos']//span//span[@class='_3jCKf -kEHD sc-jWBwVP iqHKee']//span[@class='_2i129']")
all_video.click()

x=1

time.sleep(3)
for i in driver.find_elements(By.TAG_NAME, 'tr'):
   path = "//tr["+str(x)+"]//td[2]//div[1]//a[1]//div[1]//div[1]"
   element = WebDriverWait(driver, 2).until(
   EC.presence_of_element_located((By.XPATH, path))
    )
   print(element.get_attribute("style"))
   print(x)
   x=x+1
   time.sleep(1)
   driver.execute_script("arguments[0].scrollIntoView();", element)

0 个答案:

没有答案