我正在使用以下代码使用python从网址中提取评论,但导出的csv并未包含列中的所有评论。相反,它会将数据导出到不同的列中。 我是否必须在现有代码中添加任何代码?
import requests
from unidecode import unidecode
from bs4 import BeautifulSoup
URL = "https://www.tripadvisor.in/Hotel_Review-g295424-d1735662-Reviews-
Winchester_Grand_Hotel_Apartments-Dubai_Emirate_of_Dubai/"
r = requests.get(URL)
soup = BeautifulSoup(r.content, 'html5lib')
resultsoup = soup.find_all("p", {"class" : "partial_entry"})
with open('testreview.csv', 'w') as fid:
for review in resultsoup:
review_list = review.get_text()
fid.write(unidecode(review_list))
答案 0 :(得分:-1)
您只需要在您要写入文件的行中添加换行符号(' \ n')。
您只需要在您要写入文件的行中添加换行符号(' \ n')。
with open('testreview.csv', 'w') as fid:
for review in resultsoup:
review_list = review.get_text()
fid.write(unidecode(review_list+'\n'))