婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > 分布式爬蟲(chóng)處理Redis里的數(shù)據(jù)操作步驟

分布式爬蟲(chóng)處理Redis里的數(shù)據(jù)操作步驟

熱門(mén)標(biāo)簽:太原營(yíng)銷(xiāo)外呼系統(tǒng) 地圖標(biāo)注費(fèi)用 西藏教育智能外呼系統(tǒng)價(jià)格 玄武湖地圖標(biāo)注 最簡(jiǎn)單的百度地圖標(biāo)注 地圖標(biāo)注如何即時(shí)生效 百度商家地圖標(biāo)注怎么做 竹間科技AI電銷(xiāo)機(jī)器人 小紅書(shū)怎么地圖標(biāo)注店

存入MongoDB

1.啟動(dòng)MongoDB數(shù)據(jù)庫(kù):sudo mongod

2.執(zhí)行下面程序:py2 process_youyuan_mongodb.py

# process_youyuan_mongodb.py
# -*- coding: utf-8 -*-
import json
import redis
import pymongo
def main():
 # 指定Redis數(shù)據(jù)庫(kù)信息
 rediscli = redis.StrictRedis(host='192.168.199.108', port=6379, db=0)
 # 指定MongoDB數(shù)據(jù)庫(kù)信息
 mongocli = pymongo.MongoClient(host='localhost', port=27017)
 # 創(chuàng)建數(shù)據(jù)庫(kù)名
 db = mongocli['youyuan']
 # 創(chuàng)建表名
 sheet = db['beijing_18_25']
 while True:
 # FIFO模式為 blpop,LIFO模式為 brpop,獲取鍵值
 source, data = rediscli.blpop(["youyuan:items"])
 item = json.loads(data)
 sheet.insert(item)
 try:
  print u"Processing: %(name)s %(link)s>" % item
 except KeyError:
  print u"Error procesing: %r" % item
if __name__ == '__main__':
 main()

存入 MySQL

1.啟動(dòng)mysql:mysql.server start(更平臺(tái)不一樣)

2.登錄到root用戶(hù):mysql -uroot -p

3.創(chuàng)建數(shù)據(jù)庫(kù)youyuan:create database youyuan;

4.切換到指定數(shù)據(jù)庫(kù):use youyuan

5.創(chuàng)建表beijing_18_25以及所有字段的列名和數(shù)據(jù)類(lèi)型。

6.執(zhí)行下面程序:py2 process_youyuan_mysql.py

#process_youyuan_mysql.py
# -*- coding: utf-8 -*-
import json
import redis
import MySQLdb
def main():
 # 指定redis數(shù)據(jù)庫(kù)信息
 rediscli = redis.StrictRedis(host='192.168.199.108', port = 6379, db = 0)
 # 指定mysql數(shù)據(jù)庫(kù)
 mysqlcli = MySQLdb.connect(host='127.0.0.1', user='power', passwd='xxxxxxx', db = 'youyuan', port=3306, use_unicode=True)
 while True:
 # FIFO模式為 blpop,LIFO模式為 brpop,獲取鍵值
 source, data = rediscli.blpop(["youyuan:items"])
 item = json.loads(data)
 try:
  # 使用cursor()方法獲取操作游標(biāo)
  cur = mysqlcli.cursor()
  # 使用execute方法執(zhí)行SQL INSERT語(yǔ)句
  cur.execute("INSERT INTO beijing_18_25 (username, crawled, age, spider, header_url, source, pic_urls, monologue, source_url) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s )", [item['username'], item['crawled'], item['age'], item['spider'], item['header_url'], item['source'], item['pic_urls'], item['monologue'], item['source_url']])
  # 提交sql事務(wù)
  mysqlcli.commit()
  #關(guān)閉本次操作
  cur.close()
  print "inserted %s" % item['source_url']
 except MySQLdb.Error,e:
  print "Mysql Error %d: %s" % (e.args[0], e.args[1])
if __name__ == '__main__':
 main()

總結(jié)

以上所述是小編給大家介紹的分布式爬蟲(chóng)處理Redis里的數(shù)據(jù)操作步驟,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

您可能感興趣的文章:
  • 使用Docker Swarm搭建分布式爬蟲(chóng)集群的方法示例
  • 深入理解Python分布式爬蟲(chóng)原理
  • Python 用Redis簡(jiǎn)單實(shí)現(xiàn)分布式爬蟲(chóng)的方法
  • Scrapy-redis爬蟲(chóng)分布式爬取的分析和實(shí)現(xiàn)
  • PHP一個(gè)簡(jiǎn)單的無(wú)需刷新爬蟲(chóng)
  • Python3爬蟲(chóng)全國(guó)地址信息
  • python爬蟲(chóng)獲取小區(qū)經(jīng)緯度以及結(jié)構(gòu)化地址
  • 用C#做網(wǎng)絡(luò)爬蟲(chóng)的步驟教學(xué)
  • Python數(shù)據(jù)抓取爬蟲(chóng)代理防封IP方法
  • 爬蟲(chóng)技術(shù)之分布式爬蟲(chóng)架構(gòu)的講解

標(biāo)簽:林芝 唐山 廣東 香港 贛州 揚(yáng)州 景德鎮(zhèn) 澳門(mén)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《分布式爬蟲(chóng)處理Redis里的數(shù)據(jù)操作步驟》,本文關(guān)鍵詞  分布式,爬蟲(chóng),處理,Redis,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《分布式爬蟲(chóng)處理Redis里的數(shù)據(jù)操作步驟》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于分布式爬蟲(chóng)處理Redis里的數(shù)據(jù)操作步驟的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 当阳市| 安吉县| 怀化市| 葫芦岛市| 深泽县| 甘谷县| 屏边| 嘉义县| 房产| 称多县| 岳普湖县| 临颍县| 外汇| 横峰县| 西乌| 江津市| 奈曼旗| 永昌县| 松原市| 大厂| 阿尔山市| 马山县| 大邑县| 仪陇县| 托里县| 临夏县| 板桥市| 阳高县| 德清县| 南开区| 股票| 德庆县| 克什克腾旗| 马关县| 三门县| 临夏县| 突泉县| 依兰县| 林州市| 建瓯市| 沅陵县|