How to convert a BeautifulSoup tag to JSON?

Hello Ford,

When i try your code the output says : 

 File "c:\Users\Amine\Desktop\Projet python\test3.py", line 7, in <module>

    txt = re.findall(r'goodsInfo\s*:\s*({.*})', requests.get(url).text)[0]

IndexError: list index out of range

Could please help me ? 

Thank you so much

Your code : 

import re
import json
import requests

url = 'https://eur.shein.com/Mock-neck-Brush-Stroke-Print-Bodycon-Dress-p-941649-cat-1727.html?scici=navbar_2~~tab01navbar04~~4~~real_1727~~~~0~~0&ref=www&rep=dir&ret=eur'

txt = re.findall(r'goodsInfo\s*:\s*({.*})', requests.get(url).text)[0]

data = json.loads(txt)

# print(json.dumps(data, indent=4)) # <-- uncomment to see all data

print(data['detail']['goods_name'])
print(data['detail']['brand'])
print('Num of comments:', data['detail']['comment']['comment_num'])



Answers 0

Related Articles