fp2_4 update
This commit is contained in:
@@ -2,36 +2,42 @@ from selenium import webdriver
|
|||||||
from selenium.webdriver.chrome.options import Options
|
from selenium.webdriver.chrome.options import Options
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
# Configure the Selenium driver options
|
# Configure the Selenium driver options
|
||||||
options = Options()
|
options = Options()
|
||||||
options.add_argument('--headless')
|
#options.add_argument('--headless')
|
||||||
options.add_argument('--disable-gpu')
|
options.add_argument('--disable-gpu')
|
||||||
driver = webdriver.Chrome(options=options)
|
driver = webdriver.Chrome(options=options)
|
||||||
|
|
||||||
# Load the page and extract the __NEXT_DATA__ data
|
# Load the page and extract the __NEXT_DATA__ data
|
||||||
url = 'https://www.sayweee.com/en/product/Want-Want-Senbei-Rice-Crackers/17119'
|
url = 'https://www.sayweee.com/en/product/Want-Want-Senbei-Rice-Crackers/17119'
|
||||||
driver.get(url)
|
driver.get(url)
|
||||||
|
time.sleep(5)
|
||||||
next_data_element = None
|
next_data_element = None
|
||||||
try:
|
#try:
|
||||||
next_data_element = driver.find_element(By.XPATH, '//script[contains(text(), "__NEXT_DATA__")]')
|
next_data_element = driver.find_element(By.XPATH, "//script[@type='application/ld+json']")
|
||||||
except:
|
#except:
|
||||||
print('__NEXT_DATA__ element not found')
|
# print('__NEXT_DATA__ element not found')
|
||||||
|
|
||||||
|
#time.sleep(1000)
|
||||||
if next_data_element is not None:
|
if next_data_element is not None:
|
||||||
next_data_text = next_data_element.get_attribute('innerHTML')
|
next_data_text = next_data_element.get_attribute('innerHTML')
|
||||||
|
print(next_data_text)
|
||||||
next_data_start_index = next_data_text.index('{')
|
next_data_start_index = next_data_text.index('{')
|
||||||
next_data_end_index = next_data_text.rindex('}') + 1
|
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 = next_data_text[next_data_start_index:next_data_end_index]
|
||||||
next_data = json.loads(next_data_json)
|
next_data = json.loads(next_data_json)
|
||||||
|
|
||||||
# Extract the price from the __NEXT_DATA__ data
|
# Extract the price from the __NEXT_DATA__ data
|
||||||
price = next_data['props']['pageProps']['product']['price']
|
# price = next_data['props']['pageProps']['product']['price']
|
||||||
|
print(next_data)
|
||||||
|
price = next_data['offers']['price']
|
||||||
# Print the price
|
# Print the price
|
||||||
print(price)
|
print(price)
|
||||||
else:
|
else:
|
||||||
print('__NEXT_DATA__ element not found')
|
print('__NEXT_DATA__ element not found')
|
||||||
|
|
||||||
|
time.sleep(1000)
|
||||||
# Close the Selenium driver
|
# Close the Selenium driver
|
||||||
driver.quit()
|
#driver.quit()
|
||||||
|
|||||||
Reference in New Issue
Block a user