当前位置: 首页 > news >正文

海外seo网站建设摄影照片投稿网站

海外seo网站建设,摄影照片投稿网站,知名建筑类的网站,产品设计公司起名#x1f449;博__主#x1f448;#xff1a;米码收割机 #x1f449;技__能#x1f448;#xff1a;C/Python语言 #x1f449;公众号#x1f448;#xff1a;测试开发自动化【获取源码商业合作】 #x1f449;荣__誉#x1f448;#xff1a;阿里云博客专家博主、5… 博__主米码收割机 技__能C/Python语言 公众号测试开发自动化【获取源码商业合作】 荣__誉阿里云博客专家博主、51CTO技术博主 专__注专注主流机器人、人工智能等相关领域的开发、测试技术。 Python将100个PDF文件对应的json文件存储到MySql数据库源码 目录 Python将100个PDF文件对应的json文件存储到MySql数据库源码1. 需求描述2. 结果展示3. 代码分析3. 1 导入模块3.2 数据库配置3.3 数据库连接3.4 创建数据库表3.5 数据插入函数3.6 加载和处理JSON数据3.7数据检索函数1.8 示例检索和清理 部分代码 1. 需求描述 给100篇PDF文件与其一一对应的json文件假定这一百篇PDF文件存储于D盘的名为100PDF的文件夹中json文件存储在D盘名为100JSON的文件夹中。 要求 1.利用python对接数据库将这100篇PDF和对应的JSON文件存储在名为Mypdf的数据库中。 2.写一段python代码能够调用这100篇 PDF和其对应的JSON文件。 100_PDF_MetaData.json 部分内容如下 {elsevier_05cbcb9ef5629bc25e84df43572f9d1eddb9a35f: {date: 1981-12-01T00:00:00,ref_paper: [],conference: ,keywords: [],year: 1981,author: {affiliation: [Chemistry Department, B-017, University of California at San Diego, La Jolla, CA 92093 U.S.A.,Chemistry Department, B-017, University of California at San Diego, La Jolla, CA 92093 U.S.A.],name: [R.W. Carlson,G.W. Lugmair]},last_page: 8,link: https://www.sciencedirect.com/science/article/abs/pii/0012821X81901126,abstract: Pristine samples from the lunar highlands potentially offer important information bearing on the nature of early crustal development on all the terrestrial planets. One apparently unique sample of this group of lunar crustal rocks, the feldspathic lherzolite 67667, was studied utilizing the Sm-Nd radiometric system in an attempt to define its age and the implications of that age for the evolution of the lunar highlands. Data for 67667 precisely define an isochron corresponding to an age of 4.18\u00b10.07 AE. The observed lack of disturbance of the Sm-Nd system of this sample may suggest that this time marks its crystallization at shallow depth in the lunar crust. However, the possibility that this age, as well as those of other highland rocks, indicate the time of their impact-induced excavation from regions deep enough in the lunar crust to allow subsolidus isotopic equilibrium to be produced or maintained between their constituent minerals is also considered. Taken together, bulk rock Sm-Nd data for four \u201chigh-Mg\u201d rocks, including 67667, indicate that the chemical characteristics of all their source materials were established 4.33\u00b10.08 AE ago and were intimately associated with the parent materials of KREEP. This finding provides more support for the concept of a large-scale differentiation episode early in lunar history. The possible roles of the crystallization of a global magma ocean, endogenous igneous activity, and of planetesimal impact, in producing the observed geochemical and chronological aspects of lunar highland rocks are discussed.,title: Sm-Nd age of lherzolite 67667: implications for the processes involved in lunar crustal formation,paper_id: elsevier_05cbcb9ef5629bc25e84df43572f9d1eddb9a35f,volume: 56,update_time: 2022-07-16T14:06:08.117141,journal: Earth and Planetary Science Letters,issn: 0012-821X,first_page: 1,publisher: elsevier,doi: 10.1016/0012-821X(81)90112-6},....略...}pdf文档内容如下 2. 结果展示 json数据表 关注公众号回复 “PDF数据库存储” 获取源码 论文内容数据表 关注公众号回复 “PDF数据库存储” 获取源码 3. 代码分析 当然让我们更详细地分析这段代码的每个部分 3. 1 导入模块 os用于文件和目录操作如遍历目录和打开文件。pymysql一个Python库用于连接和操作MySQL数据库。PyPDF2Python库用于读取PDF文件。json内置库用于处理JSON数据这里主要用于读取JSON文件。 3.2 数据库配置 db_config一个字典包含连接MySQL数据库所需的信息如主机、用户、密码、数据库名。 3.3 数据库连接 使用pymysql.connect建立到MySQL的连接。cursor对象用于执行SQL命令。 3.4 创建数据库表 CREATE TABLE SQL语句被用来创建两个表paper_metadata存储论文的元数据和paper_content存储论文的PDF内容。IF NOT EXISTS确保如果表已存在不会重复创建。 3.5 数据插入函数 insert_metadata将JSON中的元数据插入paper_metadata表。这里处理了如作者、出版日期等多种字段。insert_content将PDF文件的内容插入paper_content表。这里只提取了PDF的第一页内容。使用cursor.execute来执行SQL插入命令并且在每次插入后调用connection.commit来提交事务。 3.6 加载和处理JSON数据 从指定路径加载JSON文件其中包含与PDF文件相关联的元数据。遍历一个特定目录中的PDF文件使用PyPDF2读取每个文件提取第一页内容。对于每个PDF如果它的ID在JSON元数据中它的内容和元数据将被插入到数据库中。 3.7数据检索函数 retrieve_data根据paper_id从paper_metadata和paper_content表中检索信息。使用cursor.execute执行查询并通过cursor.fetchone获取结果。 1.8 示例检索和清理 使用retrieve_data函数来检索特定paper_id的数据。如果找到数据它将被打印出来如果没有会打印一条消息表示没有找到数据。最后代码清理部分关闭了数据库游标和连接。 部分代码 部分代码如下 import os import pymysql from PyPDF2 import PdfReader import json# 数据库配置 db_config {host: 127.0.0.1,user: root,password: root,database: Mypdf }# 连接数据库 connection pymysql.connect(**db_config) cursor connection.cursor()# 创建表格 - paper_metadata cursor.execute(CREATE TABLE IF NOT EXISTS paper_metadata (paper_id VARCHAR(255) PRIMARY KEY,# ...略....) )# 创建表格 - paper_content cursor.execute(...略(源码关注公众号测试开发自动化 回复 “PDF数据库存储” 获取) )# 插入数据的函数 - paper_metadata def insert_metadata(paper_id, json_data):query INSERT INTO paper_metadata (paper_id, title, date, year, abstract, authors, affiliations, last_page, first_page, link, ref_paper, conference, keywords, volume, update_time, journal, issn, publisher, doi)VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)authors , .join(json_data[author][name])affiliations , .join(json_data[author][affiliation])cursor.execute(query, (paper_id, json_data[title], json_data[date], json_data[year], json_data[abstract], authors, affiliations, json_data[last_page], json_data[first_page], json_data[link], str(json_data[ref_paper]), json_data[conference], str(json_data[keywords]), json_data[volume], json_data[update_time], json_data[journal], json_data[issn], json_data[publisher], json_data[doi]))connection.commit()...略# 检索数据的函数 def retrieve_data(paper_id):# 查询metadata表query_metadata SELECT * FROM paper_metadata WHERE paper_id %s# ...略# 查询content表query_content SELECT pdf_content FROM paper_content WHERE paper_id %s# ...略# 检索数据的示例 result retrieve_data(elsevier_05cbcb9ef5629bc25e84df43572f9d1eddb9a35f) if result:print(result) else:print(No data found for this paper ID.)# 关闭连接 cursor.close() connection.close()关注公众号回复 “PDF数据库存储” 获取源码
http://www.w-s-a.com/news/655746/

相关文章:

  • 如何建立网站教程wordpress粘帖图片
  • 广东网站备案要多久网站开发 pdf 文字版
  • 学校网站方案帮别人做钓鱼网站吗
  • 如何加强网站建设和信息宣传wordpress 搜索提示
  • 灰色网站怎么做php yaf 网站开发框架
  • 浙江建设网站首页提供做网站公司有哪些
  • 建公司网站报价公司seo是什么级别
  • 可信赖的武进网站建设中山网站建设方案
  • 网站设计方面有什么公司运动鞋网站建设目的
  • 学校门户网站流程建设方案找人做网站 多少钱
  • 网站域名更换相应内容网站策划 要求
  • 百盛联合建设集团网站开发网站的步骤
  • php做网站评价网络公司经营范围可以加技
  • 网站积分的作用保定专业网站建设
  • 莆田做网站公司电话如何提升网站访问速度
  • 网站开发流程步骤 口袋网页访问wordpress
  • 湘潭做网站的公司自助建站教程
  • 做网站推广和头条推广wordpress 验证密码错误
  • 淘宝联盟网站怎么做深圳市创想三维科技有限公司
  • 校园网站建设招标公告php网站开发什么
  • 06628 网页制作与网站开发陕西省交通建设网站
  • 做wish如何利用数据网站暗红色网站
  • 企业 网站备案 法人长春建站模板搭建
  • 网站做快照网站改版 升级的目的
  • 自己做一个网站要多少钱海外推广什么意思
  • 郑州做网站哪家专业网络基础知识大全
  • 济南制作网站企业php 调试网站
  • 互联网站管理工作细则做网站通栏模糊
  • 徐州手机网站开发公司电话青岛有名的互联网公司
  • 如何在手机做网站wordpress 网站搬迁