您好,登錄后才能下訂單哦!
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author:Aiker Zhao
@file:doutinghao.py
@time:下午8:18
"""
import requests
import re
import pymongo
from multiprocessing import Pool
MONGO_URL = 'localhost:27017'
MONGO_DB = 'doutinghao'
MONGO_TABLE = 'doutinghao'
client = pymongo.MongoClient(MONGO_URL, connect=False)
db = client[MONGO_DB]
def get_result(url):
response = requests.get(url).text
# print(reponse.text)
pattern = re.compile('<a href="(ed2k.*?)"\srel.*?title="(.*?.mp4).*?".*?>', re.S)
result = re.findall(pattern, response)
if result:
for i in result:
url, name = i
yield {
"name": name,
'url': url
}
def save_to_mongo(result):
if db[MONGO_TABLE].insert(result):
print('存儲(chǔ)到MongoDB成功', result)
return True
return False
def main(result):
# result = get_result(url)
save_to_mongo(result)
if __name__ == '__main__':
pool = Pool()
url = "https://www.xl720.com/thunder/34283.html"
item = [item for item in get_result(url)]
# print(item)
pool.map(main, item)
pool.close()
pool.join()
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。