有没有一种方法可以使用精美的汤过滤掉JavaScript中嵌入的产品ID

时间:2019-02-02 07:58:54

标签: javascript beautifulsoup

我正在为鞋子创建一个结帐机器人,并希望从html源代码中的JavaScript部分中抓取数据。我宁愿不使用字符串操作,因为它是静态的。有没有办法使用漂亮的汤或类似的东西来过滤产品信息?

这为shopify网站。我曾想过使用的findAll(“脚本”),但也有在文本许多JavaScript部分,和我讨厌硬代码脚本部分它。

这是在原始HTML的JavaScript的一部分。我想抓住产品ID,如“9913856852004”和鞋的尺寸/名称的信息。

Afterpay.products.push({
  "id": 1063026130980,
  "title": "Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White",
  "handle": "aj6599-202-nike-womens-air-vapormax-fk-moc-2-moon-black white",
  "description": "\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e",
  "published_at": "2018-12-19T13:55:25+11:00",
  "created_at": "2018-12-19T13:55:25+11:00",
  "vendor": "NIKE",
  "type": "Footwear",
  "tags": ["Footwear", "Sneakers"],
  "price": 28000,
  "price_min": 28000,
  "price_max": 28000,
  "available": true,
  "price_varies": false,
  "compare_at_price": null,
  "compare_at_price_min": 0,
  "compare_at_price_max": 0,
  "compare_at_price_varies": false,
  "variants": [{
    "id": 9913856852004,
    "title": "Moon Particle\/Black-White \/ 6",
    "option1": "Moon Particle\/Black-White",
    "option2": "6",
    "option3": null,
    "sku": "36363",
    "requires_shipping": true,
    "taxable": true,
    "featured_image": null,
    "available": true,
    "name": "Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 6",
    "public_title": "Moon Particle\/Black-White \/ 6",
    "options": ["Moon Particle\/Black-White", "6"],
    "price": 28000,
    "weight": 1500,
    "compare_at_price": null,
    "inventory_quantity": 1,
    "inventory_management": "shopify",
    "inventory_policy": "deny",
    "barcode": null
  }, {
    "id": 9913856884772,
    "title": "Moon Particle\/Black-White \/ 7",
    "option1": "Moon Particle\/Black-White",
    "option2": "7",
    "option3": null,
    "sku": "36364",
    "requires_shipping": true,
    "taxable": true,
    "featured_image": null,
    "available": true,
    "name": "Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 7",
    "public_title": "Moon Particle\/Black-White \/ 7",
    "options": ["Moon Particle\/Black-White", "7"],
    "price": 28000,
    "weight": 1500,
    "compare_at_price": null,
    "inventory_quantity": 2,
    "inventory_management": "shopify",
    "inventory_policy": "deny",
    "barcode": null
  }, {
    "id": 9913856983076,
    "title": "Moon Particle\/Black-White \/ 9",
    "option1": "Moon Particle\/Black-White",
    "option2": "9",
    "option3": null,
    "sku": "36367",
    "requires_shipping": true,
    "taxable": true,
    "featured_image": null,
    "available": false,
    "name": "Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 9",
    "public_title": "Moon Particle\/Black-White \/ 9",
    "options": ["Moon Particle\/Black-White", "9"],
    "price": 28000,
    "weight": 1500,
    "compare_at_price": null,
    "inventory_quantity": 0,
    "inventory_management": "shopify",
    "inventory_policy": "deny",
    "barcode": null
  }, {
    "id": 9913857015844,
    "title": "Moon Particle\/Black-White \/ 10",
    "option1": "Moon Particle\/Black-White",
    "option2": "10",
    "option3": null,
    "sku": "36368",
    "requires_shipping": true,
    "taxable": true,
    "featured_image": null,
    "available": true,
    "name": "Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 10",
    "public_title": "Moon Particle\/Black-White \/ 10",
    "options": ["Moon Particle\/Black-White", "10"],
    "price": 28000,
    "weight": 1500,
    "compare_at_price": null,
    "inventory_quantity": 1,
    "inventory_management": "shopify",
    "inventory_policy": "deny",
    "barcode": null
  }],
  "images": ["\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200", "\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_2.jpg?v=1545188202", "\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_3.jpg?v=1545188203", "\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_4.jpg?v=1545188206"],
  "featured_image": "\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200",
  "options": ["Color", "Size"],
  "content": "\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e"
});

我想要一些可以动态地从javascript信息中获取ID的东西。

1 个答案:

答案 0 :(得分:0)

您可以结合使用BeautifulSoupjsonre。这是真的很难不实际的URL来回答,但这里是一些可能的工作。您可以定制,使之适合您的具体使用情况。

案例1:每种产品使用不同的脚本标签。

html="""
<script>
Afterpay.products.push({"id":1063026130980,"title":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White","handle":"aj6599-202-nike-womens-air-vapormax-fk-moc-2-moon-black white","description":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e","published_at":"2018-12-19T13:55:25+11:00","created_at":"2018-12-19T13:55:25+11:00","vendor":"NIKE","type":"Footwear","tags":["Footwear","Sneakers"],"price":28000,"price_min":28000,"price_max":28000,"available":true,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":9913856852004,"title":"Moon Particle\/Black-White \/ 6","option1":"Moon Particle\/Black-White","option2":"6","option3":null,"sku":"36363","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 6","public_title":"Moon Particle\/Black-White \/ 6","options":["Moon Particle\/Black-White","6"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856884772,"title":"Moon Particle\/Black-White \/ 7","option1":"Moon Particle\/Black-White","option2":"7","option3":null,"sku":"36364","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 7","public_title":"Moon Particle\/Black-White \/ 7","options":["Moon Particle\/Black-White","7"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":2,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856983076,"title":"Moon Particle\/Black-White \/ 9","option1":"Moon Particle\/Black-White","option2":"9","option3":null,"sku":"36367","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 9","public_title":"Moon Particle\/Black-White \/ 9","options":["Moon Particle\/Black-White","9"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913857015844,"title":"Moon Particle\/Black-White \/ 10","option1":"Moon Particle\/Black-White","option2":"10","option3":null,"sku":"36368","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 10","public_title":"Moon Particle\/Black-White \/ 10","options":["Moon Particle\/Black-White","10"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_2.jpg?v=1545188202","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_3.jpg?v=1545188203","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_4.jpg?v=1545188206"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","options":["Color","Size"],"content":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e"});
</script>
<script>
something before this
Afterpay.products.push({"id":1063026130981,"title":"Nike Men's Air Vapormax FK Moc 2 - Moon\/Black\/White","handle":"aj6599-202-nike-womens-air-vapormax-fk-moc-2-moon-black white","description":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e","published_at":"2018-12-19T13:55:25+11:00","created_at":"2018-12-19T13:55:25+11:00","vendor":"NIKE","type":"Footwear","tags":["Footwear","Sneakers"],"price":28000,"price_min":28000,"price_max":28000,"available":true,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":9913856852004,"title":"Moon Particle\/Black-White \/ 6","option1":"Moon Particle\/Black-White","option2":"6","option3":null,"sku":"36363","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 6","public_title":"Moon Particle\/Black-White \/ 6","options":["Moon Particle\/Black-White","6"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856884772,"title":"Moon Particle\/Black-White \/ 7","option1":"Moon Particle\/Black-White","option2":"7","option3":null,"sku":"36364","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 7","public_title":"Moon Particle\/Black-White \/ 7","options":["Moon Particle\/Black-White","7"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":2,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856983076,"title":"Moon Particle\/Black-White \/ 9","option1":"Moon Particle\/Black-White","option2":"9","option3":null,"sku":"36367","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 9","public_title":"Moon Particle\/Black-White \/ 9","options":["Moon Particle\/Black-White","9"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913857015844,"title":"Moon Particle\/Black-White \/ 10","option1":"Moon Particle\/Black-White","option2":"10","option3":null,"sku":"36368","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 10","public_title":"Moon Particle\/Black-White \/ 10","options":["Moon Particle\/Black-White","10"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_2.jpg?v=1545188202","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_3.jpg?v=1545188203","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_4.jpg?v=1545188206"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","options":["Color","Size"],"content":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e"});
</script>
<script>
We don't need this
</script>
"""
from bs4 import BeautifulSoup
import re
import json
soup=BeautifulSoup(html,"html.parser")
scripts=soup.find_all("script",text=re.compile('Afterpay.products.push'))
product_info_list=[]
pattern = re.compile(r"\((.*?)\)")
for script in scripts:
    json_string=pattern.search(script.text).group(1)
    product_info_list.append(json.loads(json_string))
#print the items
for product in product_info_list:
    print(product['id'])
    print(product['title'])
    print("--------------------")

输出:

1063026130980
Nike Women's Air Vapormax FK Moc 2 - Moon/Black/White
--------------------
1063026130981
Nike Men's Air Vapormax FK Moc 2 - Moon/Black/White
--------------------

情况2:如果它们都是单一脚本标签内

html="""
<script>
Afterpay.products.push({"id":1063026130980,"title":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White","handle":"aj6599-202-nike-womens-air-vapormax-fk-moc-2-moon-black white","description":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e","published_at":"2018-12-19T13:55:25+11:00","created_at":"2018-12-19T13:55:25+11:00","vendor":"NIKE","type":"Footwear","tags":["Footwear","Sneakers"],"price":28000,"price_min":28000,"price_max":28000,"available":true,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":9913856852004,"title":"Moon Particle\/Black-White \/ 6","option1":"Moon Particle\/Black-White","option2":"6","option3":null,"sku":"36363","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 6","public_title":"Moon Particle\/Black-White \/ 6","options":["Moon Particle\/Black-White","6"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856884772,"title":"Moon Particle\/Black-White \/ 7","option1":"Moon Particle\/Black-White","option2":"7","option3":null,"sku":"36364","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 7","public_title":"Moon Particle\/Black-White \/ 7","options":["Moon Particle\/Black-White","7"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":2,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856983076,"title":"Moon Particle\/Black-White \/ 9","option1":"Moon Particle\/Black-White","option2":"9","option3":null,"sku":"36367","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 9","public_title":"Moon Particle\/Black-White \/ 9","options":["Moon Particle\/Black-White","9"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913857015844,"title":"Moon Particle\/Black-White \/ 10","option1":"Moon Particle\/Black-White","option2":"10","option3":null,"sku":"36368","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 10","public_title":"Moon Particle\/Black-White \/ 10","options":["Moon Particle\/Black-White","10"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_2.jpg?v=1545188202","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_3.jpg?v=1545188203","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_4.jpg?v=1545188206"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","options":["Color","Size"],"content":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e"});
Afterpay.products.push({"id":1063026130981,"title":"Nike Men's Air Vapormax FK Moc 2 - Moon\/Black\/White","handle":"aj6599-202-nike-womens-air-vapormax-fk-moc-2-moon-black white","description":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e","published_at":"2018-12-19T13:55:25+11:00","created_at":"2018-12-19T13:55:25+11:00","vendor":"NIKE","type":"Footwear","tags":["Footwear","Sneakers"],"price":28000,"price_min":28000,"price_max":28000,"available":true,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":9913856852004,"title":"Moon Particle\/Black-White \/ 6","option1":"Moon Particle\/Black-White","option2":"6","option3":null,"sku":"36363","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 6","public_title":"Moon Particle\/Black-White \/ 6","options":["Moon Particle\/Black-White","6"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856884772,"title":"Moon Particle\/Black-White \/ 7","option1":"Moon Particle\/Black-White","option2":"7","option3":null,"sku":"36364","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 7","public_title":"Moon Particle\/Black-White \/ 7","options":["Moon Particle\/Black-White","7"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":2,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913856983076,"title":"Moon Particle\/Black-White \/ 9","option1":"Moon Particle\/Black-White","option2":"9","option3":null,"sku":"36367","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 9","public_title":"Moon Particle\/Black-White \/ 9","options":["Moon Particle\/Black-White","9"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":9913857015844,"title":"Moon Particle\/Black-White \/ 10","option1":"Moon Particle\/Black-White","option2":"10","option3":null,"sku":"36368","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Nike Women's Air Vapormax FK Moc 2 - Moon\/Black\/White - Moon Particle\/Black-White \/ 10","public_title":"Moon Particle\/Black-White \/ 10","options":["Moon Particle\/Black-White","10"],"price":28000,"weight":1500,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":null}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_2.jpg?v=1545188202","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_3.jpg?v=1545188203","\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_4.jpg?v=1545188206"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/0104\/1862\/products\/Wmns_Vapormax_Moc_Moon_1.jpg?v=1545188200","options":["Color","Size"],"content":"\u003cp\u003eNike continue to modify the coveted Vapormax silhouette, bringing us the Vapormax Moc 2. The shoe features a lightweight FlyKnit upper with a gore strap in place of the regular lacing system, sitting atop the signature Vapormax midsole. Other details include synthetic overlays for added durability, heel pull tabs and subtle swoosh branding.\u003cbr\u003e\u003cbr\u003eSizes are shown in women's US. For men's sizing minus 1.5.\u003c\/p\u003e"});
</script>
<script>
We don't need this
</script>
"""
from bs4 import BeautifulSoup
import re
import json
soup=BeautifulSoup(html,"html.parser")
product_info_list=[]
product_strings=re.findall(r'\(.*\)',soup.text)
for product_string in product_strings:
    product_info_list.append(json.loads(product_string[1:-1]))

for product in product_info_list:
    print(product['id'])
    print(product['title'])
    print('------------------------')

输出:

1063026130980
Nike Women's Air Vapormax FK Moc 2 - Moon/Black/White
------------------------
1063026130981
Nike Men's Air Vapormax FK Moc 2 - Moon/Black/White
------------------------