【问题标题】:shopify scraper returning values with html elementsshopify刮刀返回带有html元素的值
【发布时间】:2021-01-31 09:01:32
【问题描述】:

此 Shopify 抓取工具正在返回带有正文的 HTML 元素,因为它支持 HTML 格式。如果没有 HTML 元素,我如何将值返回到 CSV?

'body': str(product['body_html'])

返回到 CSV 的示例:

<p><span>These seasonal and spiced cookies will warm any Fall day. Gluten-free and allergy-friendly, enjoy sweet and�soft-baked cookies full of everything you want in a snack and nothing you don't.�</span></p>

【问题讨论】:

    标签: python html csv web-scraping shopify


    【解决方案1】:

    您可以使用 HTML 解析器,例如 beautifulsoup 将所有标签字符串化:

    from bs4 import BeautifulSoup
    
    
    text_with_html = '''<p><span>These seasonal and spiced cookies will warm any Fall day. Gluten-free and allergy-friendly, enjoy sweet and�soft-baked cookies full of everything you want in a snack and nothing you don't.�</span></p>'''
    
    soup = BeautifulSoup(text_with_html, 'html.parser')
    
    print(soup.get_text(strip=True, separator=' '))
    

    打印:

    These seasonal and spiced cookies will warm any Fall day. Gluten-free and allergy-friendly, enjoy sweet and�soft-baked cookies full of everything you want in a snack and nothing you don't.�
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2021-09-07
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 2021-09-30
      相关资源
      最近更新 更多