csv文件写入是是一个个中文字符用,号隔开的
def parse_one_page(self,url):
response = requests.get(url=url,headers=self.headers)
js_data = json.loads(response.text)
# wait_time = random.randint(1,5)
# time.sleep(wait_time)
comment_list = js_data['comments']
# print(comment_list)
for comment in comment_list:
# 商品id
# goods_id = comment.get('id')
# 购买的商品名称
referenceName = comment.get('referenceName')
# 评分
# score = comment.get('score')
# 商品尺寸
# prouductSize = comment.get('productSize')
# 商品颜色
prouductColor= comment.get("productColor")
# 评论时间
# creationTime = comment.get('creationTime')
# 评论内容
content = comment.get('content')
content = content.replace('\n', ' ')
# print(prouductColor)
with open('JDcomment.csv', 'a', newline='') as csv_file:
# rows = (referenceName, prouductColor, content)
writer = csv.writer(csv_file)
writer.writerow(content)
商品信息,商品颜色,评论
半,个,月,就,降,价,六,百,块,,,意,难,平
气,死,了, ,双,十,一,降,价,了,五,百,块
售,前,问,题,抛,皮,球,,,售,后,对,接,服,务,差
我想要达到的结果
rows = (referenceName, prouductColor, content)里面只有一个参数,也可以打印完整的内容
半个月就降价六百块,意难平
气死了 双十一降价了五百块
售前问题抛皮球,售后对接服务差