forked from SVIG/python-bootcamp
Add Egg.py
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user