1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Can't get all span tags inside div element using beautifulsoup

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    I am scraping the product details page text on Amazon, but I get the data back as bullet list. I want to have the data added as a column next to other scraped data.

    csv export Amazon Product Details

    A part of the code that is working

    def get_availability(soup):
    try:
    available = soup.find("div", attrs={'id':'availability'})
    available = available.find("span").string.strip()

    except AttributeError:
    available = "Not Available"

    return available


    I mimicked this part of the code like above, but it is not working as expected

    # Function to extract Product Details
    def get_pd(soup):
    try:
    pd = soup.find("div", attrs={'id':'detailBullets_feature_div'}).text.strip()
    pd = pd.find("span").string.strip()

    except AttributeError:
    pd = ""

    return pd


    When I remove this part of the code

    pd = pd.find("span").string.strip()


    I get the bullet list, but the result is not how I want. The result should be placed next to each other instead of vertical.

    Continue reading...

Compartilhe esta Página