【问题标题】:Is there a way to use beautiful soup to filter out the product id embedded in the JavaScript有没有办法使用漂亮的汤来过滤掉嵌入在 JavaScript 中的产品 id
【发布时间】:2019-02-02 07:58:53
【问题描述】:

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

这是一个 shopify 网站。我考虑过使用 findAll("script"),但是文本中有很多 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 的东西。

【问题讨论】:

    标签: javascript beautifulsoup


    【解决方案1】:

    您可以使用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
    ------------------------
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-15
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 2020-04-17
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      相关资源
      最近更新 更多