pinglun.py-20180722

# -*- coding: utf-8 -*-
"""
Created on Thu Jul 12 15:08:33 2018

@author: wenyun.wxw
"""
import requests
import re

#https://rate.tmall.com/list_detail_rate.htm?
#itemId=567925396518  #商品id
#&spuId=960800008  #SPU比价组件 http://open.alimama.com/api/widgets.php#area1
#&sellerId=3081047815 #卖家id
#&order=3 
#&currentPage=1 #评论页码
#&append=0
#&content=1 #评论
#&tagId=
#&posi=
#&picture=
#&ua=098%23E1hvY9vEvbQvUvCkvvvvvjiPPszpljD8PFdUgj1VPmPWsjt8RFMO1j1PPsLZAj3PvphvC9vhvvCvpvyCvhQhLaGvC0RvQRAn%2BbyDCwLvTWeARFxjKOmxfBuKNB3rQjxr%2Bull8j7QD70wd56OfaClff8rakrlIUkt%2BbODCToQD70OVC69D7zyaXTJKphv8vvvvvCvpvvvvvvm6yCv2WgvvUnvphvpgvvv96CvpCCvvvm2phCvhhmEvpvVmvvC9jXCuphvmvvv92bBNpp%2F2QhvCvvvMMGtvpvhvvvvv8wCvvpvvUmm3QhvCvvhvvv%3D&isg=BPLyKgOl_UVDUcERZO6yep7lQzjKgtWR3qS4grzLHqWQT5JJpBNGLfiNO6vWP261&needFold=0
#&_ksTS=1531452327008_411
#&callback=jsonp412


#创建循环链接
urls = []
#替换页面数为i,取前100页评论
for i in list(range(1,99)):
    urls.append('https://rate.tmall.com/list_detail_rate.htm?itemId=567925396518&spuId=960800008&sellerId=3081047815&order=3&currentPage=%s' %i)

# 构建字段容器
#nickname = []
#saletype =[]
#color = []
ratecontent = []
#ratedate = []

# 循环抓取数据
for url in urls:
    content = requests.get(url).text

# 借助正则表达式使用findall进行匹配查询
    #nickname.extend(re.findall('"displayUserNick":"(.*?)"',content))
    #saletype.extend(re.findall(re.compile('套餐类型:(.*?);'),content))
    #color.extend(re.findall(re.compile('颜色分类:(.*?)","auctionTitle"'),content))
    ratecontent.extend(re.findall(re.compile('"rateContent":"(.*?)","rateDate"'),content))
    #ratedate.extend(re.findall(re.compile('"rateDate":"(.*?)","reply"'),content))
    
# 写入数据
file = open('天猫精灵评价all.csv','w')
#for i in list(range(len(nickname))):
#    file.write(','.join((nickname[i],ratedate[i],saletype[i],color[i],ratecontent[i]))+'\n')
for i in list(range(len(ratecontent))):
    file.write(ratecontent[i]+'\n')
file.close()


ratecontent = []
#读取预料 一行预料为一个文档
for line in open('天猫精灵评价all.csv', 'r').readlines():
    #print(line)
    ratecontent.append(line.strip())

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值