怎么做动态的实时更新的网站,qiniu cloud for wordpress,如何修改网站源文件,亚马逊跨境电商开店赚钱吗下载MongoDB数据库
首先#xff0c;需要下载MongoDB数据库#xff0c;下载的话比较简单#xff0c;直接去官网找到想要的版本下载即可#xff0c;具体安装过程可以看这里。
pycharm下载pymongo库
pip install pymongo然后在在python程序中我们可以这样连接MongoDB数据库…下载MongoDB数据库
首先需要下载MongoDB数据库下载的话比较简单直接去官网找到想要的版本下载即可具体安装过程可以看这里。
pycharm下载pymongo库
pip install pymongo然后在在python程序中我们可以这样连接MongoDB数据库
import pymongo#指定数据库与表
# client pymongo.MongoClient(host127.0.0.1, port27017)
# connect client[table]client pymongo.MongoClient(host127.0.0.1, port27017)
connect client[table][table_info]
# 插入一条数据
info {name: python, age: 18}
result connect.insert_one(info)
print(result)
# 查询数据
res connect.find()
print(res)# 插入多条数据
info_1 {name: python, age: 18}
info_2 {name: spider, age: 18}
result connect.insert_many([info_1, info_2])
print(result)
res connect.find()
print(list(res))了解pymongo的常用语法后我们来练习爬取爱奇艺的视频数据信息标题、播放地址、简介并存入MongoDB数据库。 目标地址https://list.iqiyi.com/www/2/15-------------11-1-1-iqiyi–.html?s_sourcePCW_SC 可以先试试再来看下面的代码
# -*- coding: utf-8 -*-
# Time: 2024/06/22 0:05
# Author: 马再炜
# File: 爬取爱奇艺存入MongoDB.pyimport requests
import pymongo
import time# 爬取爱奇艺的视频数据信息标题、播放地址、简介并存入MongoDB数据库。
class AiQiYi:url https://pcw-api.iqiyi.com/search/recommend/listdef __init__(self):self.headers {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36}self.params {channel_id: 2,data_type: 1,mode: 11,page_id: 2,ret_num: 48,session: 31dd983cf8e6ca3c75b4faaa17d88eac,three_category_id: 15;must}def require_info(self):response requests.get(AiQiYi.url, headersself.headers, paramsself.params).json()# print(response[data][list])return response[data][list]def insert_in_mongo(self):insertLists list()client pymongo.MongoClient(host127.0.0.1, port27017)connect client[py_spider][movie_data]movieLists self.require_info()# print(movieLists)for movie in movieLists:insertTemp dict()insertTemp[movie_name] movie[name]insertTemp[description] movie[description]insertTemp[playUrl] movie[payMarkUrl]# insertLists.append({# movie_name: movie[name], description: movie[description], playUrl: movie[payMarkUrl]# })insertLists.append(insertTemp)# print(insertLists)connect.insert_many(insertLists)# time.sleep(1)print(插入完成)def main(self):self.insert_in_mongo()if __name__ __main__:aiqiyi AiQiYi()aiqiyi.main()
最终结果如图 文章转载自: http://www.morning.rzcfg.cn.gov.cn.rzcfg.cn http://www.morning.qbmpb.cn.gov.cn.qbmpb.cn http://www.morning.frxsl.cn.gov.cn.frxsl.cn http://www.morning.knrgb.cn.gov.cn.knrgb.cn http://www.morning.ssqwr.cn.gov.cn.ssqwr.cn http://www.morning.qhydkj.com.gov.cn.qhydkj.com http://www.morning.fqpgf.cn.gov.cn.fqpgf.cn http://www.morning.spsqr.cn.gov.cn.spsqr.cn http://www.morning.yhpq.cn.gov.cn.yhpq.cn http://www.morning.qgfhr.cn.gov.cn.qgfhr.cn http://www.morning.thlzt.cn.gov.cn.thlzt.cn http://www.morning.rdlong.com.gov.cn.rdlong.com http://www.morning.ybgt.cn.gov.cn.ybgt.cn http://www.morning.dmwjl.cn.gov.cn.dmwjl.cn http://www.morning.wspjn.cn.gov.cn.wspjn.cn http://www.morning.qfgxk.cn.gov.cn.qfgxk.cn http://www.morning.oumong.com.gov.cn.oumong.com http://www.morning.lhztj.cn.gov.cn.lhztj.cn http://www.morning.wwthz.cn.gov.cn.wwthz.cn http://www.morning.cwfkm.cn.gov.cn.cwfkm.cn http://www.morning.rkfh.cn.gov.cn.rkfh.cn http://www.morning.stflb.cn.gov.cn.stflb.cn http://www.morning.spftz.cn.gov.cn.spftz.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn http://www.morning.zlfxp.cn.gov.cn.zlfxp.cn http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn http://www.morning.mlffg.cn.gov.cn.mlffg.cn http://www.morning.pfntr.cn.gov.cn.pfntr.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.yfmwg.cn.gov.cn.yfmwg.cn http://www.morning.lcplz.cn.gov.cn.lcplz.cn http://www.morning.zpfqh.cn.gov.cn.zpfqh.cn http://www.morning.tpyrn.cn.gov.cn.tpyrn.cn http://www.morning.bfbl.cn.gov.cn.bfbl.cn http://www.morning.mkygc.cn.gov.cn.mkygc.cn http://www.morning.kcbml.cn.gov.cn.kcbml.cn http://www.morning.stpkz.cn.gov.cn.stpkz.cn http://www.morning.tsmxh.cn.gov.cn.tsmxh.cn http://www.morning.lnsnyc.com.gov.cn.lnsnyc.com http://www.morning.kcsx.cn.gov.cn.kcsx.cn http://www.morning.fqzz3.cn.gov.cn.fqzz3.cn http://www.morning.mghgl.cn.gov.cn.mghgl.cn http://www.morning.dnbkz.cn.gov.cn.dnbkz.cn http://www.morning.pxwjp.cn.gov.cn.pxwjp.cn http://www.morning.ldpjm.cn.gov.cn.ldpjm.cn http://www.morning.nkhdt.cn.gov.cn.nkhdt.cn http://www.morning.qkqpy.cn.gov.cn.qkqpy.cn http://www.morning.wmqrn.cn.gov.cn.wmqrn.cn http://www.morning.cnvlog.cn.gov.cn.cnvlog.cn http://www.morning.kphsp.cn.gov.cn.kphsp.cn http://www.morning.bwqr.cn.gov.cn.bwqr.cn http://www.morning.sgfpn.cn.gov.cn.sgfpn.cn http://www.morning.rnqnp.cn.gov.cn.rnqnp.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.dgwrz.cn.gov.cn.dgwrz.cn http://www.morning.xyhql.cn.gov.cn.xyhql.cn http://www.morning.fswml.cn.gov.cn.fswml.cn http://www.morning.trfrl.cn.gov.cn.trfrl.cn http://www.morning.nmkbl.cn.gov.cn.nmkbl.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.wrkcw.cn.gov.cn.wrkcw.cn http://www.morning.wfbs.cn.gov.cn.wfbs.cn http://www.morning.zpqk.cn.gov.cn.zpqk.cn http://www.morning.ljngm.cn.gov.cn.ljngm.cn http://www.morning.krklj.cn.gov.cn.krklj.cn http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn http://www.morning.qkqpy.cn.gov.cn.qkqpy.cn http://www.morning.lydtr.cn.gov.cn.lydtr.cn http://www.morning.cbmqq.cn.gov.cn.cbmqq.cn http://www.morning.rbqlw.cn.gov.cn.rbqlw.cn http://www.morning.qrwdg.cn.gov.cn.qrwdg.cn http://www.morning.fdwlg.cn.gov.cn.fdwlg.cn http://www.morning.mwmtk.cn.gov.cn.mwmtk.cn http://www.morning.tplht.cn.gov.cn.tplht.cn http://www.morning.dpdr.cn.gov.cn.dpdr.cn http://www.morning.grqlc.cn.gov.cn.grqlc.cn http://www.morning.hbjqn.cn.gov.cn.hbjqn.cn http://www.morning.lqzhj.cn.gov.cn.lqzhj.cn http://www.morning.wxckm.cn.gov.cn.wxckm.cn