def update_object(collection, id): id = int(id) if collection not in CRUD_COLLECTIONS: return respond({'error': 'Page not found'}, 404) if id in NON_MODIFIABLE[collection]: return respond({'error': 'Cannot be modified'}, 400) data = request.json if data is None or data == {}: return respond({'error': 'Please provide the data to update'}, 400) db = MongoAPI(DATABASE, collection) if not db.exists({'_id': id}): return respond({'error': 'The collection has no record with the provided ID'}, 400) content_to_update = {} for field_name in UPDATEABLE_FIELDS[collection]: if field_name in data: content_to_update[field_name] = int(data[field_name]) if type(data[field_name]) == str and data[field_name].isdigit() else data[field_name] if len(content_to_update) > 0: response = db.update({'_id': id}, content_to_update) return respond(response, 200) else: return respond({'error': 'You can only update {} for {}'.format(', '.join(UPDATEABLE_FIELDS[collection]), collection)}, 400)
lastest_anthor=lastest_tag.span.text lastest_reply_time=lastest_tag.a.text lastest_reply_time=modify_time(lastest_reply_time) data_list.append([name,link,author_name,author_link,built_time,reply_num, view_num,lastest_anthor,lastest_reply_time]) for row in data_list: connection.update( {'link':row[1]},#primary key { 'title':row[0], 'author_name':row[2], 'author_link':row[3], 'built_time':row[4], 'reply_num':row[5], 'view_num':row[6], 'lastest_author':row[7], 'lastest_reply_time':str(row[8]), } ) time.sleep(3) print("第"+str(i)+'页over!')
data_list.append([ title, site, author, posttime, postlink, reply, view, last_reply, date_time ]) #date_time不是str形式 return data_list link1 = "https://bbs.hupu.com/bxj-" for i in range(1, 11): #虎扑步行街第十一页就要登陆了 link = link1 + str(i) soup = get_page(link) post_all = soup.find("ul", class_="for-list") post_list = post_all.find_all( 'li') #find()查找第一个匹配结果出现的地方,find_all()找到所有匹配结果出现的地方。 data_list = get_data(post_list) hupu_post = MongoAPI("localhost", 27017, "hupu", "post") for each in data_list: hupu_post.update({'帖子链接:': each[1]}, { '帖子名:': each[0], '帖子链接:': each[1], '作者:': each[2], '发帖时间:': each[3], '作者主页:': each[4], '回复数:': each[5], '浏览量:': each[6], '最新回复:': each[7], '最新回复时间': str(each[8]) }) # print(each) time.sleep(3) #3秒一页