在BeautifulSoup python中打印相同的名称、价格和链接

在BeautifulSoup python中打印相同的名称、价格和链接,python,selenium,beautifulsoup,python-requests,Python,Selenium,Beautifulsoup,Python Requests,如何获取所有产品的详细信息它打印相同的内容,但我希望其他产品也能提供详细信息 以下是我要从中获取所有产品数据的链接: 会发生什么? 他们的缩进与您的print 它们是产品网格的类的唯一元素 如何修复? 检查打印的缩进,它应该在打印项目的循环中 将您的选择更改为: content= soup.find_all('div',class_='product-card') 好处:相反,最好使用新语法findAll() 示例 import requests from bs4 import Beau

如何获取所有产品的详细信息它打印相同的内容,但我希望其他产品也能提供详细信息 以下是我要从中获取所有产品数据的链接:

会发生什么?
  • 他们的缩进与您的
    print
  • 它们是
    产品网格的
    的唯一元素
  • 如何修复?
  • 检查
    打印的缩进,它应该在打印项目的循环中

  • 将您的选择更改为:

    content= soup.find_all('div',class_='product-card')
    
  • 好处:相反,最好使用新语法
    findAll()

  • 示例

    import requests
    from bs4 import BeautifulSoup
    import pandas as pd
    import numpy as np
    from selenium import webdriver
    
    
    url= "https://www.nike.com/gb/w/womens-lifestyle-shoes-13jrmz5e1x6zy7ok"
    driver = webdriver.Chrome(executable_path=r'C:\Program Files\ChromeDriver\chromedriver.exe')
    driver.get(url)
    pageSource = driver.page_source
    for n in range(10):
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        soup = BeautifulSoup(pageSource, 'lxml')
        content= soup.find_all('div',class_='product-card')
        content 
        for item in content:
            title= item.find('div',class_ = 'product-card__title').text
            link = item.find('a', {'class': 'product-card__link-overlay'})['href']
            price=item.find('div',class_ ='product-price css-11s12ax is--current-price').text
            print(title,price,link)
    
    import requests
    from bs4 import BeautifulSoup
    import pandas as pd
    import numpy as np
    from selenium import webdriver
    
    
    url= "https://www.nike.com/gb/w/womens-lifestyle-shoes-13jrmz5e1x6zy7ok"
    driver = webdriver.Chrome(executable_path=r'C:\Program Files\ChromeDriver\chromedriver.exe')
    driver.get(url)
    pageSource = driver.page_source
    for n in range(10):
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        soup = BeautifulSoup(pageSource, 'lxml')
        content= soup.find_all('div',class_='product-card')
        content 
        for item in content:
            title= item.find('div',class_ = 'product-card__title').text
            link = item.find('a', {'class': 'product-card__link-overlay'})['href']
            price=item.find('div',class_ ='product-price css-11s12ax is--current-price').text
            print(title,price,link)