def search_db():

    keys2x = raw_input("请输入搜索关键字:")
#for keys2x in search_list:
    file_name = '/Users/llm/PycharmProjects/' + keys2x + '.getone.txt'
    print "开始进行mongodb数据库操作:"
    #
    db = pymongo_imp.get_db()
    my_collection = pymongo_imp.get_collection(db)


    xlist=pymongo_imp.get_many_docs(db,keys2x)

    for listnet in xlist:
        mag_1=listnet['Magnet_Link'].encode('gb2312')
        with open(file_name, 'a') as p:  # '''Note''':Append mode, run only once!

            p.write("%s \n \n" % mag_1)  ##!!encode here to utf-8 to avoid encoding
Exemple #2
0
                        #链接地址
                        file_name = ks + '_' + page  # 让文件按页码保存,避免一个文件中链接数量太多。
                        if movie_li.find('a', attrs={
                                'rel': 'magnet'
                        }) is None:  ####>>>>>>>      如果为非空,那么就获取。
                            pass
                        else:
                            detail_mag = movie_li.find(
                                'a',
                                attrs={'rel': 'magnet'
                                       })['href']  #####>>>>>>7     获取磁力链接地址。
                            #上面获取了磁力链接。❕
                            print detail_mag
                            #with open(file_name, 'a') as p:  # '''Note''':Append mode, run only once!
                            #    p.write("%s \n \n" % detail_mag)  ##!!encode here to utf-8 to avoid encoding

                            #获取了磁力链接之后开始存入数据库。
                            print "开始进行mongodb数据库操作:"
                            #存入数据库
                            db = pymongo_imp.get_db()
                            my_collection = pymongo_imp.get_collection(db)

                            pymongo_imp.insert_one_doc(db, detail_name, detail,
                                                       detail_mag)

                            print "截止目前,数据库中存放条目数量:%s个" % int(
                                my_collection.count())

        except:
            pass