我试图从一个网站的双卷曲{}内的字符串中获取一个特定的数据。怎样才能取出这些数据?以下是网站上双卷发的剪报:
<div class="swatch-data">
{"thumbnailImageUrl":"https://www.jbl.com.ph/dw/image/v2/AAUJ_PRD/on/demandware.static/-/Sites-masterCatalog_Harman/default/dw367304ef/JBL_Endurance-SPRINT_Product-Image_Black_Front-1605x1605px.jpg?sw=270&sh=330&sm=fit&sfrm=png","productUrl":"https://www.jbl.com.ph/JBL+Endurance+SPRINT.html?cgid=in-ear-headphones&dwvar_JBL%20Endurance%20SPRINT_color=Black-GLOBAL-","productSupportUrl":"","productID":"JBLENDURSPRINTBLK","orderable":false,"availability":{"message":"","status":"NOT_AVAILABLE"},"price":{"unitLabel":"each","priceType":"standard","salesPrice":"N/A"},"realprice":{"salesPrice":"N/A"},"badges":["new"],"buttonText":"Sold Out","showProdLimit":{"status":""},"CTAEnable":true,"commerceSiteFlag":false,"showPromoTimerFlag":false,"isProProd":false}
</div>
谢谢。在
编辑: 我确实用了beauthoulsoup4,只是我真的只是个傻瓜,还没来过JSON。在
带bs4的示例
输出
^{pr2}$你看到的实际上是一个JSON。在
首先需要去掉div。使用BeautifulSoup是推荐的方法之一。在
然后,可以使用
json.loads(str)
加载字符串。在相关问题 更多 >
编程相关推荐