skip to Main Content

This is the link. I am trying to scrape the entire description texts. It is all under a div class called "station-tabs-content-inner". But some texts are under the lists tag and some are under the p tag with no specific class name. Can someone help me to get all the texts inside this div, regardless of their tags?

2

Answers


  1. Use class="description" for selecting the tag and then .get_text():

    import requests
    from bs4 import BeautifulSoup
    
    url = "https://foodkoreadubai.com/products/teazen-organic-barley-sprout-powder-2g-x-10-sticks"
    
    soup = BeautifulSoup(requests.get(url).content, "html.parser")
    desc = soup.select_one(".description").get_text(strip=True, separator="n")
    
    print(desc)
    

    Prints:

    📚 Description
    Soft, Delicious Barley Sprout Powder: TEAZEN sprout barley powder is a young barley leaf grown about 25cm after germination. Produced by hygienic automated equipment and crushed by ultra fine grinder It is an excellent green product
    Korean Organic Barley Sprout Powder: Signed an MOU supply of barley sprout with Haenam-gun, Korea. We produce TEAZEN sprouted barley powder rich in dietary fiber and chlorophyll by grinding the sprouted barley carefully grown in the clean and beautiful Haenam-gun without squeezing it.
    Individual Stick Packaging: Hygienic, easy-to-store stick type
    Consume in a variety of ways according to your taste: Put 1 barley sprout powder stick into milk (soy milk) or 250ml of mineral water and enjoy. You can enjoy by adding 1 barley sprout powder stick to 100ml of yogurt, or sprinkle it on salads!
    Contains Chlorophyll and Dietary Fiber. Barley Sprout contains 20 times more dietary fiber than sweet potato.
    Chlorophyll’s reputation as a health and wellness supplement predates the recent TikTok-fueled interest by decades. It has long been touted for a wide range of health benefits, including:
    Cancer prevention.
    Healing wounds.
    Skin care and acne treatment.
    Weight loss.
    Controlling body odor.
    Relieving constipation and gas.
    Boosting energy.
    📹 Videos
    🧐 How-To
    Consume in a variety of ways according to your taste: Put 1 barley sprout powder stick into milk (soy milk) or 250ml of mineral water and enjoy. You can enjoy by adding 1 barley sprout powder stick to 100ml of yogurt, or sprinkle it on salads!
    
    Login or Signup to reply.
  2. This is indeed interesting HTML source.

    If you inspect the source, you’ll see that the data is alos availbae in JSON format:

    enter image description here

    So, grab the data from there:

    import json
    
    import requests
    from bs4 import BeautifulSoup
    
    
    URL = "https://foodkoreadubai.com/products/teazen-organic-barley-sprout-powder-2g-x-10-sticks#description"
    
    soup = BeautifulSoup(requests.get(URL).content, "html.parser")
    
    content = soup.find("script", id="ProductJson-product-template").string
    
    json_data = json.loads(content)["description"]
    
    soup2 = BeautifulSoup(json_data, "html.parser")
    
    for tag in soup2.select("ul:nth-of-type(1) span, p, ul:nth-of-type(2) li"):
        print(tag.get_text(strip=True, separator="nn"))
    

    Prints:

    Soft, Delicious Barley Sprout Powder: TEAZEN sprout barley powder is a young barley leaf grown about 25cm after germination. Produced by hygienic automated equipment and crushed by ultra fine grinder It is an excellent green product
    Korean Organic Barley Sprout Powder: Signed an MOU supply of barley sprout with Haenam-gun, Korea. We produce TEAZEN sprouted barley powder rich in dietary fiber and chlorophyll by grinding the sprouted barley carefully grown in the clean and beautiful Haenam-gun without squeezing it.
    Individual Stick Packaging: Hygienic, easy-to-store stick type
    Consume in a variety of ways according to your taste: Put 1 barley sprout powder stick into milk (soy milk) or 250ml of mineral water and enjoy. You can enjoy by adding 1 barley sprout powder stick to 100ml of yogurt, or sprinkle it on salads!
    Contains Chlorophyll and Dietary Fiber. Barley Sprout contains 20 times more dietary fiber than sweet potato.
    Chlorophyll’s reputation as a health and wellness supplement predates the recent TikTok-fueled interest by decades. It has long been touted for a wide range of health benefits, including:
    Cancer prevention.
    Healing wounds.
    Skin care and acne treatment.
    Weight loss.
    Controlling body odor.
    Relieving constipation and gas.
    Boosting energy.
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search