概述
1 Author:jum2 from yibanban.common.common import *
3
4
5 def get_article_id(): #获取文章id
6 json_data_list ={7 "channel_id": 自己的,8 "puid": 自己的,9 "page": 1,10 "size": 10,11 "orderby": "updateTime",12 "Sections_id": -1,13 "need_notice": 0,14 "group_id": 自己的,15 "my": 0,16 "lastId": 自己的17 }18 res = person.post(url="http://www.yiban.cn/forum/article/listAjax", data=json_data_list)19 #获取json数据
20 json_list0 =res.json()21 #数据筛选
22
23 #article_list = re.findall("id(.*?)Channel_id", str(json_list0))
24 article_list = jsonpath.jsonpath(json_list0, '$..id')25 article_list1 = re.findall("([56789][0-9]{7})", str(article_list))26 #for i in article_list:
27 #n = re.findall("d+",i)
28 #for m in n:
29 #article_list1.append(m)
30 #jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
31 print(json_list0)32 print(type(article_list))33 print(article_list)34 print(article_list1)35 returnarticle_list136
37
38 #文章点赞
39 def good(): #点赞
40 article_id =change_page()41 for i inarticle_id:42 print(i)43 article_data ={44 "article_id": i,45 "channel_id": 自己的,46 "puid": 自己的47 }48 good_res = person.post(url="http://www.yiban.cn/forum/article/upArticleAjax", data=article_data, headers={49 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',50 'Accept': 'application/json, text/javascript, */*; q=0.01',51 'Accept-Language': 'zh-CN,zh;q=0.9',52 })53 print(good_res)54
55
56 #文章评论
57 def comment(): #评论
58 article_id =change_page()59 for i inarticle_id:60 print(i)61 article_data ={62 "channel_id": 自己的,63 "puid": 自己的,64 "article_id": i,65 "content": "弟子规",66 "reply_id": 0,67 "syncFeed": 1,68 "isAnonymous": 069 }70 good_res = person.post(url="http://www.yiban.cn/forum/reply/addAjax", data=article_data,71 headers={72 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',73 'Accept': 'application/json, text/javascript, */*; q=0.01',74 'Accept-Language': 'zh-CN,zh;q=0.9',75 })76 print(good_res)77
78
79 #翻页
80 def change_page(): #翻页
81 num_page = 1
82 article_list2 =[]83 for num in range(10):84 json_data_list ={85 "channel_id": 281421,86 "puid": 7245623,87 "page": num_page,88 "size": 10,89 "orderby": "hotScore",90 "Sections_id": -1,91 "need_notice": 0,92 "group_id": 457740,93 "my": 094 }95 num_page += 1
96 res = person.post(url="http://www.yiban.cn/forum/article/listAjax", data=json_data_list)97 #获取json数据
98 json_list0 =res.json()99 #数据筛选
100 #article_list = re.findall(".*id(.*)Channel_id.*", json_list0)
101 article_list = jsonpath.jsonpath(json_list0, '$..id')102 #jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
103 print(json_list0)104 article_list1 = re.findall("([56789][0-9]{7})", str(article_list))105 for a inarticle_list1:106 article_list2.append(a)107 #jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
108 print(json_list0)109 print(type(article_list))110 print(article_list)111 print(article_list1)112 print(article_list2)113 returnarticle_list2114
115
116 #添加文章
117 defarticle_add():118 article_data ={119 "puid": 自己的,120 "pubArea": 自己的,121 "title": "test",122 "content": "
this is robot auto article!!!!!
",123 "isNotice": "false",124 "dom": ".js-submit"125 }126 article_data_res = person.post(url="http://www.yiban.cn/forum/article/addAjax", data=article_data, headers={127 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',128 'Accept': 'application/json, text/javascript, */*; q=0.01',129 'Accept-Language': 'zh-CN,zh;q=0.9',130 }131 )132 print(article_data_res.json())133
134
135 #添加投票
136 def vote_add(): #投票
137 vote_data ={138 "puid": 自己的,139 "scope_ids": 自己的,140 "title": "换个姿势再来一次",141 "subjectTxt": None,142 "subjectPic": None,143 "options_num": 3,144 "scopeMin": 1,145 "scopeMax": 1,146 "minimum": 1,147 "voteValue": "2019-07-21 13:15",148 "voteKey": 2,149 "public_type": 0,150 "isAnonymous": 1,151 "voteIsCaptcha": 0,152 "istop": 1,153 "sysnotice": 2,154 "isshare": 1,155 "rsa": 1,156 "dom": ".js-submit",157 "group_id": 自己的,158 "subjectTxt_1": "vote1--",159 "subjectTxt_2": "vote2",160 "subjectTxt_3": "vote3"
161 }162 vote_data_res = person.post(url="http://www.yiban.cn/vote/vote/add", data=vote_data, headers={163 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',164 'Accept': 'application/json, text/javascript, */*; q=0.01',165 'Accept-Language': 'zh-CN,zh;q=0.9', })166 print(vote_data_res.json())167
168
169 #http://www.yiban.cn/Newgroup/showMorePub/group_id/457740/puid/7245623/type/3/page/1
170 #初始化投票,评论
171 defget_vote_url():172 for i in range(50):173 start_url = "http://www.yiban.cn/Newgroup/showMorePub/group_id/457740/puid/7245623/type/3/page/{0}".format(i)174 resp = person.get(url=start_url)175 response =Selector(resp)176 url_list = response.css('.vote-itd2 a::attr(href)').extract()177 next_url = response.css('.pager .next::attr(href)').extract()178 print(next_url) #下一页url
179 print(url_list) #整页投票url
180 for i inurl_list:181 vote_id = re.findall("vote_id/(.*?)/puid", i)182 author_id = re.findall("actor_id/(.*?)/status", i)183 #print(author_id)
184 #print(vote_id)
185 #print(type(vote_id))
186 #vote_url = "http://www.yiban.cn{0}".format(i)
187 #"pagetype": 2, (1代表未过期,2代表已过期)
188 #提取网页过期时间, 与当前时间做对比
189 #vote / vote / showDetail / vote_id / 54280789 / puid / 7245623 / group_id / 457740 / actor_id / 12806206 / status / 1
190 vate_data ={191 "vote_id": vote_id[0],192 "uid": 自己的,193 "puid": 自己的,194 "pagetype": 1,195 "group_id": 自己的,196 "actor_id": 自己的,197 "top_power": "f",198 "edit_power": "f",199 "end_power": "f",200 "del_power": "f",201 "block_power": "f",202 "isSchoolVerify": 1,203 "is_public": "f",204 "is_anonymous": "t",205 "token": "",206 "out_power": "f",207 "isMember": "",208 "url%5BgetVoteDetail%5D": "vote%2Fvote%2FgetVoteDetail",209 "url%5Boutput%5D": "%2Fvote%2FExpand%2Foutput",210 "rl%5BgetCommentDetail%5D": "vote%2Fvote%2FgetCommentDetail",211 "url%5BaddComment%5D": "vote%2Fvote%2FaddComment",212 "url%5BeditLove%5D": "vote%2Fvote%2FeditLove",213 "url%5Bvote%5D": "vote%2Fvote%2Fact",214 "url%5BsetIsTop%5D": "vote%2FExpand%2FsetIsTop",215 "url%5BsetManualEndVote%5D": "vote%2FExpand%2FsetManualEndVote",216 "url%5BdelVote%5D": "vote%2FExpand%2FdelVote",217 "url%5BdelComment%5D": "vote%2Fvote%2FdelComment",218 "url%5BshieldVote%5D": "vote%2FExpand%2FshieldVote",219 "url%5BgetAnonymous%5D": "vote%2FExpand%2FgetAnonymous",220 "url%5BuserInfo%5D": "user%2Findex%2Findex",221 "isLogin": 1,222 "isOrganization": 0,223 "ispublic": 0,224 }225 vote_res = person.post(url="http://www.yiban.cn/vote/vote/getVoteDetail", data=vate_data, cookies=cookies,226 headers={227 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',228 'Accept': 'application/json, text/javascript, */*; q=0.01',229 'Accept-Language': 'zh-CN,zh;q=0.9'})230 response_f =vote_res.json()231 #print(response_f)
232 #print(type(response_f))
233 dict1 = response_f['data']234 dict_l = dict1['vote_list']235 dict_t = dict1['option_list']236 #print(dict_t)
237
238 #选取全部voptions_id 投票选项id
239 v_list =[]240 for i indict_t:241 v_list.append(dict(i)["id"])242 print(v_list)243
244 #提取是否已投票
245 v_list1 =[]246 for m indict_t:247 try:248 v_list1.append(dict(m)["is_vote"])249 exceptKeyError:250 pass
251 print(v_list1)252
253 #min
254 minimum = int(dict_l['minimum']) #投票数 单选or多选
255 scopeMax = int(dict_l['scopeMax'])256
257 #mount_id
258 mount_id = int(dict_l['mount_id']) #投票数 单选or多选
259
260 #end_time
261 end_time = dict_l['voteValue'] + ":00" #结束时间
262
263 #时间转时间戳
264 timeArray = time.strptime(end_time, "%Y-%m-%d %H:%M:%S") #时间数组
265 timeStamp = int(time.mktime(timeArray)) #时间戳
266 print(timeStamp)267 if cmp_time(int(timeStamp)) == 1 and len(v_list1) == 0: #判断是否过期或已投票
268 voptions_id =voptions_id_chiose(minimum, v_list)269 vate_choise(vote_id[0], author_id[0], minimum, scopeMax, voptions_id) #投票
270 vate_comment(vote_id, author_id, mount_id) #评论
271 else:272 vate_comment(vote_id, author_id, mount_id)273
274
275 #def vote_chenge(next_url):
276 #if next_url:
277 #next_url ="{0}next_url".format("www.yiban.cn/")
278 #else:
279 #brack
280 #ret
281
282
283 #判断多选or单选
284 defvoptions_id_chiose(minimum, v_list):285 importrandom286 if minimum == 1:287 voptions_id =[]288 i =random.randint(0, minimum)289 voptions_id.append(v_list[i])290 voptions_id1 = [str(i) for i in voptions_id] #遍历各元素使之成为字符元素
291 str_voptions_id = "".join(voptions_id1)292 #单选
293 else:294 n =len(v_list)295 m =random.sample(range(0, n), minimum)296 voptions_id =[]297 for i inm:298 voptions_id.append(v_list[i])299 print(voptions_id)300 voptions_id1 = [str(i) for i in voptions_id] ## 遍历各元素使之成为字符元素
301 str_voptions_id = ",".join(voptions_id1)302 #多选
303 returnstr_voptions_id304
305
306 #判断投票是否过期
307 defcmp_time(end_time):308 n_time =time.time()309 pagetype = 1
310 if int(n_time) >end_time:311 pagetype = 2
312 returnpagetype313
314
315 #选择投票
316 defvate_choise(vote_id, author_id, minimum, scopeMax, voptions_id):317 vate_data ={318 "puid": 自己的,319 "group_id": 自己的,320 "vote_id": vote_id,321 "actor_id": author_id,322 "voptions_id": voptions_id,323 "minimum": minimum,324 "scopeMax": scopeMax,325 }326 res = person.post(url="http://www.yiban.cn/vote/vote/act", data=vate_data, cookies=cookies,327 headers={328 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',329 'Accept': 'application/json, text/javascript, */*; q=0.01',330 'Accept-Language': 'zh-CN,zh;q=0.9'})331 print(res.json())332
333
334 #投票评论
335 defvate_comment(vote_id, author_id, mount_id):336 comment_data ={337 "mountid": mount_id,338 "msg": "换个姿势再来一次",339 "group_id": 自己的,340 "actor_id": 自己的,341 "vote_id": vote_id,342 "author_id": author_id,343 "puid": 自己的,344 "reply_comment_id": 0,345 "reply_user_id": 0,346 }347 res = person.post(url="http://www.yiban.cn/vote/vote/addComment", data=comment_data, cookies=cookies,348 headers={349 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',350 'Accept': 'application/json, text/javascript, */*; q=0.01',351 'Accept-Language': 'zh-CN,zh;q=0.9'})352 print(res.json())353
354
355 #http://www.yiban.cn/vote/vote/getVoteDetail
356 importthreading357 if __name__ == '__main__':358 login(user, password)359 [vote_add() for i in range(20)]360 for _ in range(30):361 #t1 = threading.Thread(target=vote_add)
362 #t2 = threading.Thread(target=article_add)
363 t3 = threading.Thread(target=get_vote_url)364 #t1.start()
365 #t2.start()
366 t3.start()
最后
以上就是传统蜜粉为你收集整理的python 网站 批量 投票_python requests 简单实现易班自动登录,批量_文章发布,投票发布,评论,点赞,v2.0...的全部内容,希望文章能够帮你解决python 网站 批量 投票_python requests 简单实现易班自动登录,批量_文章发布,投票发布,评论,点赞,v2.0...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复