Files
python-bootcamp/Egg.py
T
2023-04-26 19:18:57 -04:00

34 lines
576 B
Python

#!/usr/bin/env python
# coding: utf-8
# In[1]:
import requests
url = 'https://www.sayweee.com/zh/product/Vital-Farms-Pasture-Raised-Eggs--Large-18-count/40709'
response = requests.get(url)
html_content = response.text
html_content
# In[2]:
from lxml import html
tree = html.fromstring(html_content)
script = tree.xpath('//script[@id="__NEXT_DATA__"]/text()')[0]
next_data = script.split('__NEXT_DATA__ = ')[1].split(';</script>')[0]
# In[ ]:
import json
data = json.loads(next_data)
price = data['props']['initialState']['pdp']['product']['price']
print(price)