对python的评价

编程入门 行业动态 更新时间:2024-10-18 20:26:38

对python的<a href=https://www.elefans.com/category/jswz/34/1767599.html style=评价"/>

对python的评价

旅游景点代码(地址要用手机版的携程搜自己想搜的景点):

import urllib.request

from bs4 import BeautifulSoup

import pymysql.cursors

import requests

import json

import datetime

def deal_json_invaild(data):

data = data.replace("\n", "").replace("\r", "").replace("\n\r", "").replace("\r\n", "").replace("\t", "").replace("\\\"","\"").replace("","")

data = data.replace('":"{"', "**testPasswors**5")\

.replace('":"', '&&testPassword&&')\

.replace('","', "$$testPassword$$")\

.replace('":{"', "**testPasswors**1")\

.replace('"},"', "**testPasswors**2")\

.replace(',"', "**testPasswors**3")\

.replace('{"', "@@testPassword@@")\

.replace('"}', "**testPassword**")\

.replace('":', "**testPasswors**4")\

data = data.replace('"', '”')\

.replace("**testPasswors**5","\":{\"").replace('&&testPassword&&', '":"').replace('$$testPassword$$', '","').replace('**testPasswors**1','":{"').replace('**testPasswors**2','"},"').replace('@@testPassword@@', '{"').replace('**testPassword**','"}').replace('**testPasswors**3',',"').replace('**testPasswors**4','":').replace('\\"','\"').replace(' ','').replace("resourceExtraInfo ","resourceExtraInfo").replace("\n", "").replace("\r", "").replace("\n\r", "").replace("\r\n", "").replace("\t", "").replace(r"\"","\"").replace("","").replace("}\"","}")

return data

headers={

"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko",

"Content-Type": "application/json"

}

f = open("data.txt","w",encoding='utf8')

for x in range(302,303):

# 综合评价

payload={

"CommentResultInfoEntity": {"BusinessId": "16588","BusinessType": 11,"ChannelType": 7,"CommentTagId": 0,"ImageFilter": 'false',"PageIndex": x,"PageSize": 10,"PoiId": 0,"SortType": 3,"StarType": 0,"TouristType": 0,"VideoImageHeight": 392,"VideoImageWidth": 700},"contentType": "json",

"head": {"auth": "","cid": "09031081211299101374","ctok": "","cver": "1.0","extension": [{"name": "protocal", "value": "https"}],"lang": "01","sid": "8888","syscode": "09"}

}

#好评

# payload={

# "CommentResultInfoEntity": {"BusinessId": "16588","BusinessType": 11,"ChannelType": 7,"CommentTagId": -11,"ImageFilter": 'false',"PageIndex": x,"PageSize": 10,"PoiId": 0,"SortType": 3,"StarType": 0,"TouristType": 0,"VideoImageHeight": 392,"VideoImageWidth": 700},"contentType": "json",

# "head": {"auth": "","cid": "09031081211299101374","ctok": "","cver": "1.0","extension": [{"name": "protocal", "value": "https"}],"lang": "01","sid": "8888","syscode": "09"}

# }

# #差评

# payload={

# "CommentResultInfoEntity": {"BusinessId": "16588","BusinessType": 11,"ChannelType": 7,"CommentTagId": -11,"ImageFilter": 'false',"PageIndex": x,"PageSize": 10,"PoiId": 0,"SortType": 3,"StarType": 0,"TouristType": 0,"VideoImageHeight": 392,"VideoImageWidth": 700},"contentType": "json",

# "head": {"auth": "","cid": "09031081211299101374","ctok": "","cver": "1.0","extension": [{"name": "protocal", "value": "https"}],"lang": "01","sid": "8888","syscode": "09"}

# }

r = requests.post('=09031081211299101374&__gw_appid=99999999&__gw_ver=1.0&__gw_from=10650019636&__gw_platform=H5', json=payload,headers=headers)

soup = BeautifulSoup(r.text,'html.parser')

soup = str(soup)

soup = deal_json_invaild(soup)

a = json.loads(soup)

# print(a)

for j in range(len(a["CommentResult"]["CommentInfo"])):

datetime1 = int(a["CommentResult"]["CommentInfo"][j]["PublishTime"][6:16]) #留言时间 这里是/Date()格式 里面是时间戳 js才能转换

dateArray = datetime.datetime.utcfromtimestamp(datetime1)

otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S")

address,level='None','None'

print(not a["CommentResult"]["CommentInfo"][j]["UserInfoModel"])

if a["CommentResult"]["CommentInfo"][j]["UserInfoModel"]:

address = str(a["CommentResult"]["CommentInfo"][j]["UserInfoModel"]["UserDistrictName"]) #用户地址

level = str(a["CommentResult"]["CommentInfo"][j]["UserInfoModel"]["MedalName"]) #用户级别

dd = "总评分:" +str(a["CommentResult"]["CommentInfo"][j]["TotalStar"]) + "\t评论时间:"+ otherStyleTime +" \t用户地址:"+address+" \t用户会员级别:"+level+" \t 评论:"+ a["CommentResult"]["CommentInfo"][j]["Content"]

print("第{0}列 第{1}个 {2}".format(x,j,dd))

f.write(dd+'\n')

中间一大堆replace是携程json很多不规则的地方 需要替换 想data:"{}"这种结构

发现只能搜前3000条,后面就搜不到了,不知道什么情况

还有综合评价和好评差评是分开的

用网页模拟点击:

这个参数0是综合 -11是好评 -12差评

更多推荐

对python的评价

本文发布于:2024-03-14 08:11:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1736024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:评价   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!