已关闭,该问题需要details or clarity,目前不接受回答。
**想要改进此问题?**通过editing this post添加详细信息并澄清问题。
8天前关闭
Improve this question
你好,我是一个在Python中创建基于GUI的代码的新手。如何通过传递Month_name
和Year_Num
值将下面的完整代码转换为GUI?
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.wunderground.com/")
time.sleep(10)
driver.maximize_window()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="wuSearch"]'))).send_keys("new york")
#WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., 'New York City')]"))).click()
time.sleep(10)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="wuForm"]/search-autocomplete/ul/li[2]/a'))).click()
History = driver.find_element("xpath",'//*[@id="inner-content"]/div[2]/lib-city-header/div[2]/lib-subnav/div/div[3]/ul/li[5]/a').click()
time.sleep(5)
Monthly = driver.find_element("xpath",'//*[@id="inner-content"]/div[2]/div[1]/div[1]/div[1]/div/lib-link-selector/div/div/div/a[3]').click()
time.sleep(5)
Month_name = 'July'
Month_Selection = driver.find_element("xpath",'//*[@id="monthSelection"]')
Month_Selection.send_keys(Month_name)
Yean_Num = '2019'
Year_Selection = driver.find_element("xpath",'//*[@id="yearSelection"]')
Year_Selection.send_keys(Yean_Num)
# View Data
SelectedData = driver.find_element(By.ID,'dateSubmit').click()
Data= WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH,'//*[@id="inner-content"]/div[2]/div[1]/div[5]/div[1]/div/lib-city-history-observation/div/div[2]/table'))).text #extract daily average temp from that day and place
1条答案
按热度按时间42fyovps1#
用你提供的代码将你的代码移动到一个函数
def searchWeb(month,year)
中然后,您可以运行以下代码,使用命令
searchWeb(value['--MONTH--'],value['--YEAR--'])
调用该函数,其中print语句为: