'%(save_img,title1,title2) def get_data(f_dir, dir,bk_pic_dir,save_pic_dir): world = f_dir.replace('.txt', '') world = world.replace('\xe2\x80\x8b', '') world = world.replace(' ', '') dicts = {i: '' for i in punctuation} punc_table = str.maketrans(dicts) world = world.translate(punc_table) world = world.replace('(', '') world = world.replace(')', '') world = world.replace('?', '') world = world.replace('?', '') world = world.replace(':', '') world = world.replace(':', '') world = world.replace('!', '') world = world.replace('!', '') world = world.replace('“', '') world = world.replace('"', '') world = world.replace('”', '') world = world.replace('-', '') world = world.replace('——', '') world = world.replace(',', '') world = world.replace(',', '') world = world.replace('|', '') world = world.replace('、', '') world = world.replace('(', '') world = world.replace(')', '') world = world.strip() world = remove_upprintable_chars(world) world = world[0:20] # if '_' not in world and not world.endswith('】'): if '_' not in world: url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd=%s&csor=16&pwd=%s' % ( world, world) c = requests.get(url) data = c.json() if 'g' not in data or len(data['g']) <= 2: print('数据不足,尝试1', world) world = world[0:15] url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd=%s&csor=16&pwd=%s' % (world, world) c = requests.get(url) data = c.json() if 'g' not in data or len(data['g']) <= 2: print('--尝试10个字--', world) world = world[0:10] url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd=%s&csor=16&pwd=%s' % (world, world) c = requests.get(url) data = c.json() if 'g' not in data or len(data['g']) <= 2: print('--尝试9个字--', world) world = world[0:9] url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd=%s&csor=16&pwd=%s' % (world, world) c = requests.get(url) data = c.json() if 'g' not in data or len(data['g']) <= 2: print('--尝试8个字--', world) world = world[0:8] url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd=%s&csor=16&pwd=%s' % (world, world) c = requests.get(url) data = c.json() if 'g' not in data or len(data['g']) <= 2: print('--尝试7个字--', world) world = world[0:7] url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd=%s&csor=16&pwd=%s' % (world, world) c = requests.get(url) data = c.json() if 'g' not in data or len(data['g']) <= 2: print('--尝试6个字--', world) world = world[0:6] url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd=%s&csor=16&pwd=%s' % (world, world) c = requests.get(url) data = c.json() return c = data['g'] w_list = random.sample(c, 3) rstr = "[\/\\\:\*\?\"\<\>\|]" # '/ \ : * ? " < > |' #print (w_list[0]['q']) #print (w_list[1]['q']) #print (w_list) title = re.compile('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]').sub('', w_list[0]['q']) title = re.sub(rstr, "", title) # 替换为下划线 title2 = re.compile('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]').sub('', w_list[1]['q']) title2 = re.sub(rstr, "", title2) # 替换为下划线 title3 = re.compile('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]').sub('', w_list[2]['q']) title3 = re.sub(rstr, "", title3) # 替换为下划线 # 随机挑选一张图片 bk_pic = random.choice([i for i in os.listdir(bk_pic_dir) if i.endswith('.png') or i.endswith('.jpg')]) pic_dir = os.path.join(bk_pic_dir,bk_pic) # title2 = f_dir.split('.')[0] pic = save_pic(title,title2,pic_dir,save_pic_dir) # 保存图片 with open(os.path.join(dir, f_dir), 'r+', encoding='utf-8') as f: print(f_dir.replace('.txt', '')) try: content = f.read() except Exception as e: print('文本错误') return f.seek(0, 0) f.write('
以上是【bd】,想了解更多相关内容,请访问
作为老牌一站式企业服务平台,我们(www.wjx66.cn)提供工商注册、财务服务、社保服务、商标服务、各类创业套餐等早期创业公司需要的泛法律服务。
联系在线客服或者提交需求,即可办理相关业务,或咨询24小时人工客服电话 15578329440 / 13768976670
10年金质服务 专业可见
15578329440 / 13768976670
服务时间:9:00-18:00