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

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

有沒(méi)有辦法讓硒只給我今天的數(shù)據(jù)?

有沒(méi)有辦法讓硒只給我今天的數(shù)據(jù)?

我正在嘗試創(chuàng)建一個(gè)腳本來(lái)告訴我當(dāng)天的潮汐水平selenium,但它會(huì)為我提供整周的所有數(shù)據(jù)。我怎么讓它只給我今天的數(shù)據(jù)?from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as EC import timeimport datetimedriver = webdriver.Chrome('/Users/judeslater/Downloads/chromedriver')driver.get('https://magicseaweed.com/Nosara-Surf-Report/445/Tide/')WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="msw-js-tide-list"]')))Day_of_Week = datetime.datetime.today().weekday()Break_Key = Day_of_Week + 1element = driver.find_elements_by_id('msw-js-tide-list')intDay = datetime.date(year=2000, month=12, day=1).weekday()days = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]def contains_word(string, target):    return target in string   for value in element:    Ocean_Data = value    print(Ocean_Data.text)    time.sleep(1)    if contains_word(str(Ocean_Data), days[Break_Key]) == True:       break    else:        continue    break    driver.quit()
查看完整描述

2 回答

?
HUH函數(shù)

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

你有很多錯(cuò)誤,但主要是你的


find_elements_by_id('msw-js-tide-list')

它為您提供了所有日期作為一個(gè)元素的表格。


你應(yīng)該在最后使用更復(fù)雜的xpathwith來(lái)將每一天作為單獨(dú)的元素 - 然后你可以過(guò)濾它。/div


find_elements_by_xpath('//*[@id="msw-js-tide-list"]/div')

您不必添加+1到Day_of_Week因?yàn)閜ython開(kāi)始索引0


如果你想得到明天然后更好地使用


tomorrow = today + datetime.timedelta(days=1)

0或者當(dāng)你得到時(shí)使用模數(shù)移動(dòng)到7


Break_Key = (Day_of_Week + 1) % 7

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

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

import datetime


days = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]


today = datetime.datetime.today()

#tomorrow = today + datetime.timedelta(days=1)

#day_of_week = tomorrow.weekday()

day_of_week = today.weekday()

selected_day = days[day_of_week]



driver = webdriver.Chrome('/Users/judeslater/Downloads/chromedriver')

#driver = webdriver.Firefox()

driver.get('https://magicseaweed.com/Nosara-Surf-Report/445/Tide/')


WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="msw-js-tide-list"]')))


all_days = driver.find_elements_by_xpath('//*[@id="msw-js-tide-list"]/div')


for ocean_data in all_days:

    if selected_day in ocean_data.text:

        print(ocean_data.text)

        break


driver.quit()

如果您想要今天的數(shù)據(jù),那么它可能始終是表格中的第一天,因此您all_days[1]無(wú)需檢查即可使用selected_day


隱藏div在 HTML 中,所以我必須使用[1]而不是來(lái)[0]獲取今天的數(shù)據(jù)。


from selenium import webdriver

from selenium.webdriver.common.keys import Keys

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

import datetime


driver = webdriver.Chrome('/Users/judeslater/Downloads/chromedriver')

#driver = webdriver.Firefox()

driver.get('https://magicseaweed.com/Nosara-Surf-Report/445/Tide/')


WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="msw-js-tide-list"]')))


all_days = driver.find_elements_by_xpath('//*[@id="msw-js-tide-list"]/div')


ocean_data = all_days[1] # there is one hidden `div` which I have to skip to get today's data

print(ocean_data.text)


driver.quit()

我可以使用[2]in做同樣的事情xpath(因?yàn)閜ython開(kāi)始索引0但xpath開(kāi)始于1)并在 word 中使用find_element_...without char只得到一個(gè)結(jié)果selement


ocean_data = driver.find_element_by_xpath('//*[@id="msw-js-tide-list"]/div[2]')

print(ocean_data.text)

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

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

import datetime


driver = webdriver.Chrome('/Users/judeslater/Downloads/chromedriver')

#driver = webdriver.Firefox()

driver.get('https://magicseaweed.com/Nosara-Surf-Report/445/Tide/')


WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="msw-js-tide-list"]')))


ocean_data = driver.find_element_by_xpath('//*[@id="msw-js-tide-list"]/div[2]')

print(ocean_data.text)


driver.quit()


查看完整回答
反對(duì) 回復(fù) 2023-06-13
?
吃雞游戲

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

for value in element:

為什么不使用 element[0] 而不是這個(gè) for 循環(huán),因?yàn)槟恍枰摿斜淼牡谝粋€(gè)元素('msw-js-tide-list'),它給出了今天的日期。


Ocean_Data = element[0]

print(Ocean_Data.text)

time.sleep(1)

if contains_word(str(Ocean_Data), days[Break_Key]) == True:

   break


查看完整回答
反對(duì) 回復(fù) 2023-06-13
  • 2 回答
  • 0 關(guān)注
  • 166 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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