我不断获得一个输出(下图),它在excel中每列写一个字符。我做错了什么?
r= requests.get(url)
soup = BeautifulSoup(r.content)
listing_title= soup.find_all("div",{"class":"listingTitle"})
car_info_data = soup.find_all("li",{"class": "titleCol"})
with open('testinggggg.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
for item in car_info_data: #Car name ;
print(str(item.contents[1].text))
writer.writerow(str(item.contents[1].text))
答案 0 :(得分:1)
您需要将列值列表传递到writerow()
,但目前您正在传递字符串。替换:
writer.writerow(str(item.contents[1].text))
使用:
writer.writerow([str(item.contents[1].text)])