第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我在通過 selenium python 抓取內(nèi)容時(shí)遇到錯(cuò)誤

我在通過 selenium python 抓取內(nèi)容時(shí)遇到錯(cuò)誤

眼眸繁星 2023-03-08 16:14:56
我正在通過 selenium 在https://www.indeed.ae/jobs-in-dubai上抓取工作結(jié)果的標(biāo)題。我認(rèn)為 .text 不起作用。我正在通過轉(zhuǎn)到主網(wǎng)站的 selenium 運(yùn)行代碼,輸入選擇性關(guān)鍵字,然后從結(jié)果中刪除所有標(biāo)題。但是我收到錯(cuò)誤,我該如何解決這個(gè)錯(cuò)誤這是我的代碼import timefrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.keys import KeysPath = "C:\Program Files (x86)\chromedriver.exe"driver = webdriver.Chrome(Path)driver.get("https://indeed.ae/")print(driver.title)search = driver.find_element_by_name("l")search.send_keys("Dubai")search.send_keys(Keys.RETURN)try:    td = WebDriverWait(driver, 10).until(        EC.presence_of_element_located((By.ID, "resultsCol"))    )    divs = td.find_elements_by_tag_name("div")    for div in divs:        header = div.find_element_by_class_name("title")        print(header)finally:    driver.quit()driver.quit()我收到以下錯(cuò)誤Job Search | IndeedTraceback (most recent call last):  File "C:/Users/hp/Desktop/python projects/selenium-pycharm/selenium-bot.py", line 24, in <module>    header = div.find_element_by_class_name("title")  File "C:\Users\hp\Desktop\python projects\selenium-pycharm\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 398, in find_element_by_class_name    return self.find_element(by=By.CLASS_NAME, value=name)  File "C:\Users\hp\Desktop\python projects\selenium-pycharm\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 659, in find_element    {"using": by, "value": value})['value']  File "C:\Users\hp\Desktop\python projects\selenium-pycharm\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute    return self._parent.execute(command, params)Process finished with exit code 1提前致謝
查看完整描述

1 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

您找不到標(biāo)題,因?yàn)槟鷱?resultsCol 中獲取了所有的 div。這意味著有些 div 有標(biāo)題,有些則沒有。


嘗試這個(gè) :


try:

    td = WebDriverWait(driver, 10).until(

        EC.presence_of_element_located((By.ID, "resultsCol"))

    )

    divs = td.find_elements_by_tag_name("div")

    #print(divs)

    for div in divs:

        try:

            header = div.find_element_by_class_name("title")

            print(header.text)

        except:

            continue

finally:

    driver.quit()


driver.quit()

將標(biāo)題作為輸出:


Receptionist

Administrative Assistant/ Document Controller

RECEPTIONIST

ADMIN OFFICER IN UAE

Data Entry Assistant (Fresh Graduate)

Receptionist

Replenishment Associate - Light Household - Hypermarket

DOCUMENT CONTROLLER

School Administrative Assistant - Dubai

ACCOUNTANT


查看完整回答
反對(duì) 回復(fù) 2023-03-08
  • 1 回答
  • 0 關(guān)注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)