0
我使用下面的代碼來使用python從網址中提取評論,但導出的csv不包含列中的所有評論。相反,它將數據導出到不同的列中。 我必須添加任何代碼到現有的代碼嗎?Tripadvisor網頁抓取使用python
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))
我推薦使用'csv.writer'作爲csv文件(https://docs.python.org/2/library/csv.html) – Peri461