diff --git a/fp2_9.py b/fp2_9.py index b4cf022..f02d9c3 100644 --- a/fp2_9.py +++ b/fp2_9.py @@ -25,6 +25,7 @@ timeout = 5 url = 'https://www.sayweee.com/en/product/Want-Want-Senbei-Rice-Crackers/17119' driver.get(url) time.sleep(5) +''' next_data_element = driver.find_element(By.XPATH, "//script[@type='application/ld+json']") if next_data_element is not None: next_data_text = next_data_element.get_attribute('innerHTML') @@ -34,7 +35,8 @@ if next_data_element is not None: next_data = json.loads(next_data_json) else: print('__NEXT_DATA__ element not found') - +''' + # Define callback function for Pub/Sub messages def callback(message): # Extract zip code from message data @@ -42,18 +44,29 @@ def callback(message): print(f"Received zip code: {zip_code}") # Enter zip code in the input field and click the "Check" button - zip_input = driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div/div[2]/div[2]/div/div[1]/form/div/div/div[1]/div/div/div[2]/input') + zip_input = driver.find_element(By.XPATH, '/html/body/div[2]/div/header/div[3]/div/div/div[2]/div[1]/div/div/div[1]') zip_input.clear() zip_input.send_keys(zip_code) - check_button = driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div/div[2]/div[2]/div/div[1]/form/div/div/div[1]/div/div/div[3]/div') + check_button = driver.find_element(By.XPATH, '/html/body/div[5]/div/div[2]/div/div[2]/div[2]/div/div[1]/form/div/div/div[1]/div/div/div[3]/div') check_button.click() time.sleep(2) # Extract the price of rice crackers for this zip code try: + ''' price_element = driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div[1]/div/div/div[2]/div[2]/div[1]/div[4]/div[1]/div') price = price_element.text.strip()[1:] print(price) + ''' + next_data_element = driver.find_element(By.XPATH, "//script[@type='application/ld+json']") + next_data_text = next_data_element.get_attribute('innerHTML') + next_data_start_index = next_data_text.index('{') + next_data_end_index = next_data_text.rindex('}') + 1 + next_data_json = next_data_text[next_data_start_index:next_data_end_index] + next_data = json.loads(next_data_json) + price = next_data['offers']['price'] + # Print the price + print(price) except: price = 'Price not found' finally: