Add Egg.py

This commit is contained in:
Sloetjes
2023-04-26 19:18:57 -04:00
parent 2c113bed43
commit ba730af7cb
+33
View File
@@ -0,0 +1,33 @@
#!/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)