class JPP:
def __init__(self):
# Create headless Chrome and specify download folder code
self.driver = webdriver.Chrome() # options=self.options
# Below is the current time-based -12 hours + 24 hours class variable generation code (omitted)
# Skip site login-related methods
def set_datetime_int_search(self):
# Code for entering date, time, etc. on the website and pressing the Lookup button
def return_skd(self):
html = self.driver.page_source
df = pd.read_html(html)[0]
logger.debug('df called')
return df
# Omit Other Class Methods
# Omission of Other Codes
csv_downloader = JPP()
csv_downloader.connect_to(site)
while True:
try:
csv_downloader.set_datetime_int_search()
if 'df1' not in globals():
df1 = csv_downloader.return_skd() # Problematic part
print(df1)
logger.debug(f'waiting for {JPP_SKD_UPDATE_config.config.interval} sec')
time.sleep(JPP_SKD_UPDATE_config.config.interval)
df2 = csv_downloader.return_skd() #Normal expression
print(df2)
if csv_downloader.compare_old_new(df2, df1):
break
csv_downloader.skd_update()
df1 = df2
else:
break
time.sleep(JPP_SKD_UPDATE_config.config.interval)
except Exception as e:
print(e)
df1=csv_downloader.return_skd() #Problematic part
df2 = csv_downloader.return_skd() #Normal expression
It was called by the same method, but the result is different. I think df1 brought up the screen when I first entered the Internet site, and df2 brought it up based on the time I set. If you try to call again after escaping the while phrase with break, you will get a normal result (same as df2).
Why is df1 the same class method, but the result is different? I will attach the results below
And if you bundle up and run the code from the beginning, it becomes a normal inquiry . I'd appreciate it if you could tell me why.
df1
Unnamed: 0_level_0 DATE FLT ... CGO PLD OTH FCST PLD
Unnamed: 0_level_1 DATE FLT ... Unit: LBS Unit: LBS Unit: LBS
0 1 2022-11-08 271 ... NaN NaN 17811
1 2 2022-11-08 222 ... NaN NaN 33799
2 3 2022-11-08 643 ... NaN NaN 18814
3 4 2022-11-08 202 ... NaN NaN 30447
4 5 2022-11-08 272 ... NaN NaN 15359
# a heavy policy
14 15 2022-11-08 220 ... NaN NaN 17480
15 16 2022-11-08 3 ... NaN NaN 26888
16 17 2022-11-08 273 ... NaN NaN 9537
17 18 2022-11-08 214 ... NaN NaN 29364
18 19 2022-11-08 61 ... NaN NaN 17588
[19 rows x 15 columns]
df2
Unnamed: 0_level_0 DATE FLT ... CGO PLD OTH FCST PLD
Unnamed: 0_level_1 DATE FLT ... Unit: LBS Unit: LBS Unit: LBS
0 1 2022-11-08 271 ... NaN NaN 17811
1 2 2022-11-09 271 ... NaN NaN 20780
2 3 2022-11-09 222 ... NaN NaN 28318
3 4 2022-11-08 222 ... NaN NaN 33799
4 5 2022-11-08 643 ... NaN NaN 18814
# a heavy policy
50 51 2022-11-08 211 ... NaN NaN 33040
51 52 2022-11-07 211 ... NaN NaN 31918
52 53 2022-11-08 647 ... NaN NaN 32938
53 54 2022-11-07 281 ... NaN NaN 32233
54 55 2022-11-08 281 ... NaN NaN 32233
[55 rows x 15 columns]
I solved it. When I put in the rest code as shown below, it came out according to the time I designated...
time.Sleep (seconds) # Added code
df1 = csv_downloader.return_skd() # Problematic part
© 2024 OneMinuteCode. All rights reserved.