final project update
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import http.client
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
conn = http.client.HTTPSConnection("www.sayweee.com")
|
||||
payload = ''
|
||||
headers = {}
|
||||
conn.request("GET", "/en/product/Pete-and-Gerry-s-Organic-Large-Brown-Eggs/65902?category=dairy02", payload, headers)
|
||||
res = conn.getresponse()
|
||||
data = res.read()
|
||||
|
||||
# Parse the HTML page content using ElementTree
|
||||
root = ET.fromstring(data.decode('utf-8'))
|
||||
|
||||
if root is not None:
|
||||
# Find the script element with __NEXT_DATA__ data
|
||||
next_data_element = None
|
||||
for script_element in root.iter('script'):
|
||||
if script_element.text is not None and '__NEXT_DATA__' in script_element.text:
|
||||
next_data_element = script_element
|
||||
break
|
||||
|
||||
# Extract the __NEXT_DATA__ data
|
||||
if next_data_element is not None:
|
||||
next_data_text = next_data_element.txt
|
||||
next_data_start_index = next_data_text.index('{')
|
||||
next_data_end_index = next_data_text.rindex('}') + 1
|
||||
next_data_json = next_data_text[next_data_start_index:next_data_end_index]
|
||||
print(next_data_json)
|
||||
else:
|
||||
print('__NEXT_DATA__ element not found')
|
||||
else:
|
||||
print('Failed to parse HTML content')
|
||||
Reference in New Issue
Block a user