Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

python实现endnote文献批量关联PDF

endnote直接导入文献的PDF可以直接识别到期刊、作者等相关信息,但是部分文件会出现识别出错的情况,中文文献就更不用说了。都得自己先下载引文格式,再去一个个的关联本地的PDF文件。为此老白写了一个python的脚本,可以实现在已经存在endnote library情况下,批量关联本地的pdf文件。详细说明如下:

python实现endnote文献批量关联PDF插图

1.endnote导出原library库

在endnote软件左上角,点击导出,选择xml格式(参考文献格式自选)

python实现endnote文献批量关联PDF插图1

2.endnote关联文件代码解读

从xml文件里面,我们可以分析下面两种代码

有文献关联文件的特征代码

<urls><pdf-urls><url>file://{}</url></pdf-urls></urls>

无文献关联文件特征代码

<urls></urls>

实现思路 我们可以简单的通过搜索替换的方式,将没有关联文献的替换为关联了文献的即可

3.python脚本编写

脚本如下,其中keywords.txt就是存放你的文献的位置的,456.xml是导出的endnote库

import re

def replace_urls(xml_file_path):
    replacements = []
    
    # 从文件中读取关键词并添加到替换列表中
    keywords_file_path = r"C:Usersxcbtmw.comDesktopkeywords.txt"
    with open(keywords_file_path, 'r', encoding='utf-8') as file:
        for line in file:
            keyword = line.strip()
            replacements.append(keyword)

    count = 0

    def replace(match):
        nonlocal count
        replacement = replacements[count]
        count += 1
        return "<urls><pdf-urls><url>file://{}</url></pdf-urls></urls>".format(replacement)

    with open(xml_file_path, 'r', encoding='utf-8') as file:
        xml_content = file.read()

    pattern = r"<urls></urls>"
    result = re.sub(pattern, replace, xml_content)
    
    # 新建结果文件并保存替换后的内容
    result_file_path = r"C:Usersxcbtmw.comDesktopresult.xml"
    with open(result_file_path, 'w', encoding='utf-8') as file:
        file.write(result)

    print("替换后的XML已保存至:" + result_file_path)

xml_file_path = r"C:Usersxcbtmw.comDesktop456.xml"

replace_urls(xml_file_path)

由于保存文件名可能不一致,keywords.txt需要自行填入,如果你的文件都是在同一个文件夹下,可以先获取所有文件名,再统一构造路径即可。

如果不在,那么建议使用everything搜索工具获取。keywords.txt文件示例如下:

F:资料工作备份xcbtmw.com你的文件路径sdf.pdf
F:资料工作备份xcbtmw.com你的文件路径xml.pdf
F:资料工作备份xcbtmw.com你的文件路径mxf.pdf

4.导入result.xml

填写好对应的文件位置和内容后,就生成了result.xml文件,再导入到endnote即可。

5.个人建议

把所有的文献移动到一个文件夹下,路径就可以批量获取了。

D:DowloadexploreA_comparison_of_the_application_of_block_theory_and_3D_block_cutting_analysis.pdf
D:DowloadexploreA_fast_mesh_model_for_block_generation_in_tunnels.pdf
D:DowloadexploreA_novel_approach_to_investigating_3D_fracture_connectivity_in_ultrahigh_steep_rock_slopes.pdf
D:DowloadexploreComparison_of_rock_discontinuity_mean_trace_length_and_density_estimation_methods_using_discontinuity_data_from_an_outcrop_in_Wenchuan_area__China.pdf

python实现endnote文献批量关联PDF插图2

温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
未整理

《视频号直播付费五场0粉起号课》新手秘籍

2023-11-28 0:00:00

未整理

2023最新飞机即时通讯系统源码 PC+Android+IOS+WEB四端

2023-11-29 0:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索