问题描述
我正在尝试从该网站抓取数据(价格 + 品牌)。该代码实际上有效,但我只能在 sublime 文本编辑器上看到数据,而无法将其转换为 CSV 文件。此外,我收到此错误消息:
AttributeError: 'NoneType' object has no attribute 'div'
这是我的代码:
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
PATH = "/Users/Ziye/Desktop/Python/chromedriver"
def get_html(url):
driver = webdriver.Chrome(PATH)
driver.get(url)
return driver.page_source
def main ():
rows = []
url = "https://www.yoox.com/de/damen/kleidung/shoponline/michael%20kors_md#/Md=403&d=10321&dept=clothingwomen&gender=D&page=2&season=X"
html = get_html(url)
soup = BeautifulSoup(html,"lxml")
cards = soup.find_all("div",{"class": "col-8-24"})
print(len(cards))
for card in cards:
print(card.find(class_="itemData text-center").div.get_text())
print(card.find(class_="price").get_text())
row = {'Brand': card.find(class_="brand font-bold text-uppercase").get_text(),'Price': card.find(class_="price").get_text()}
rows.append(row)
df = pd.DataFrame(rows)
df.to_csv('file.csv',index=False)
if __name__ == "__main__":
main()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)