diff --git a/Egg.py b/Egg.py new file mode 100644 index 0000000..ffcc550 --- /dev/null +++ b/Egg.py @@ -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(';')[0] + + +# In[ ]: + + +import json + +data = json.loads(next_data) +price = data['props']['initialState']['pdp']['product']['price'] +print(price) +