def make_comment_dict(topic_url, rv_comment, cookie_no, pic_url, pic_id): # 组装回帖的参数 verify_code = "" if pic_url == "" and pic_id == "": pic_url, pic_id = doubanutils.get_verify_code_pic(topic_url, cookie_no) else: if len(pic_url): pic_path = tools.save_pic_to_disk(pic_url) img = Image.open(pic_path) img = img.convert('RGBA') w, h = img.size[0], img.size[1] point_list = gen_white_black_points(img) reduce_noisy(w, h, point_list) img.putdata(point_list) img.save("rebuild.png") verify_code = wordrecognition.get_word_in_pic("rebuild.png") verify_code = verify_code.lower() comment_dict = { "ck": doubanutils.get_form_ck_from_cookie(cookie_no), "rv_comment": rv_comment, "start": 0, "img":"", "captcha-solution": verify_code, "captcha-id": pic_id, "submit_btn": "发送" } return comment_dict
def make_comment_dict(topic_url, rv_comment): # 组装回帖的参数 pic_url, pic_id = doubanutil.get_verify_code_pic(topic_url) verify_code = "" if len(pic_url): pic_path = tools.save_pic_to_disk(pic_url) verify_code = wordrecognition.get_word_in_pic(pic_path) comment_dict = { "ck": doubanutil.get_form_ck_from_cookie(), "rv_comment": rv_comment, "start": 0, "captcha-solution": verify_code, "captcha-id": pic_id, "submit_btn": "加上去" } return comment_dict
def make_comment_dict(topic_url, rv_comment): # 组装回帖的参数 from nltk.corpus import words pic_url, pic_id = doubanutil.get_verify_code_pic(topic_url) verify_code = "" while verify_code =='': if len(pic_url): verify_codeinword = False pic_path = tools.save_pic_to_disk(pic_url) rebuild_path=identify_code.recognize_url(pic_path) verify_code = wordrecognition.get_word_in_pic(rebuild_path) verify_code.replace('/','l') verify_code.replace('!', 'i') verify_code.replace(' ', '') verify_code.replace('.', '') if len(verify_code)>=4: if verify_code in words.words() or verify_code.lower() in words.words(): comment_dict = { "ck": doubanutil.get_form_ck_from_cookie(), "rv_comment": rv_comment, "start": 0, "captcha-solution": verify_code, "captcha-id": pic_id, "submit_btn": "发送" } verify_codeinword = True return comment_dict else: pic_url, pic_id = doubanutil.get_verify_code_pic(topic_url) print(pic_url) verify_code = "" else: pic_url, pic_id = doubanutil.get_verify_code_pic(topic_url) print(pic_url) verify_code = "" comment_dict = { "ck": doubanutil.get_form_ck_from_cookie(), "rv_comment": rv_comment, "start": 0, "captcha-solution": verify_code, "captcha-id": pic_id, "submit_btn": "发送" } return comment_dict
def make_topic_dict(group_id, rev_title, rev_text): # 组装发帖需要的参数 topic_new_url = doubanurl.DOUBAN_GROUP + str(group_id) + "/new_topic" pic_url, pic_id = doubanutil.get_verify_code_pic(topic_new_url) verify_code = "" if len(pic_url): pic_path = tools.save_pic_to_disk(pic_url) verify_code = wordrecognition.get_word_in_pic(pic_path) topic_dict = { "ck": doubanutil.get_form_ck_from_cookie(), "rev_title": rev_title, "rev_text": rev_text, "captcha-solution": verify_code, "captcha-id": pic_id, "rev_submit": "好了,发言" } return topic_dict