【发布时间】:2020-06-23 03:04:23
【问题描述】:
<html>
<body>
<p>
{"products":[{"id":2069443051648,"title":"BornxRaised Indian Summer Print Button-Up Shirt - Multi","handle":"bxrb4010smpt-mlt"}]
</p>
</body>
</html>
嗨,我对 bs4 和网络抓取非常陌生。我正在尝试制作一个返回产品信息的应用程序,例如项目的 ID、标题和句柄。上面的 html 代码来自一个 shopify 网站,是我目前正在使用的。下面我发布了到目前为止我在提取内容方面的成果
import requests
from bs4 import BeautifulSoup
source = requests.get('https://kith.com/products.json').text
soup = BeautifulSoup(source, 'lxml')
p = soup.find('p')
text = list(p.children)[0]
print('')
print(text.strip())
返回:
{"products":[{"id":2069443051648,"title":"BornxRaised Indian Summer Print Button-Up Shirt - Multi","handle":"bxrb4010smpt-mlt"}]
我遇到了一些问题,将其进一步简化为仅显示 ID、标题和句柄。有没有人有什么建议?我什至可能把这一切都搞错了,我在这里有点被挖掘出来了..
【问题讨论】:
标签: python beautifulsoup python-requests shopify extract