基于Selenium的IEEE批量RIS引用下载

近期为了写一份综述,需要将大量的文章引用插入到文章中去。由于平时看论文都是用onenote做文献管理,对写作时添加参考文献没有一点儿用处。
在文章中添加参考文献的思路笔者只知道两种,一种是使用latex写作,添加参考文献时使用BibTex格式。其二是使用word写作,然后在word中添加参考文献。
由于此次笔者使用的是word写作,添加参考文献就显得格外困难,恰好,EndNote在word中的插件可以很方便的添加参考文献。另一方面,由于参考文献大部分来源于IEEE,而向EndNote导入IEEE文献一般使用RIS格式。
具体可参考这个链接,不再多说。
综上,可以得到笔者的需求
1.在IEEE上下载已知标题的论文的RIS引用
2. 将下载的RIS格式添加到EndNote中
笔者有以下的条件:
1.所有需要引用的参考文献pdf文件均已经存放在同一个文件夹中,且pdf文件名为论文标题。
2.已经在EndNote 中打开了一个Library。
3.默认使用EndNote打开RIS文件

注意:由于各种虽然知道原因但不知道解决方法的问题,以及各种不知道原因的问题,下载结果并不一定是所需的,使用时还需要自行检验

python版本:3.6.8
chrome版本:101.0.4951.41
运行环境:vscode 1.66.2
EndNote版本:EndNote X9(Bld 12062)

下面就是使用python实现需求的代码

from selenium import webdriver  

import os
import time
import re

# 一些基础操作的参考
# selenium基础教程 https://zhuanlan.zhihu.com/p/111859925
# chromedriver下载地址 https://chromedriver.storage.googleapis.com/index.html
# 兄弟节点定位和父节点定位 https://blog.csdn.net/xuemeilu/article/details/124484986
# 通过系统默认方式打开文件 https://www.cnpython.com/qa/73652
# 字符串中是否包含汉字 https://blog.csdn.net/shouwangcc/article/details/48157643
# 参考了一些其他人的工作
# https://blog.csdn.net/qq_37189298/article/details/117394233
# https://blog.csdn.net/weixin_50097774/article/details/121564394
def downloadRIS(filename,flag):
    try:
        flag = flag +1
        searchBox =  driver.find_element_by_xpath('//input[@aria-label="Enter search text"]')
        searchButton = driver.find_element_by_xpath('//div[@class="search-icon"]')
        searchBox.click()
        searchBox.send_keys(filename.split(".")[0])
        searchButton.click()
        time.sleep(2)       # 由于等候时间较短,当搜索结果较多时会报错,从而可以手动寻找需要的文献,同时也有可能因为延迟稍大而报错
        checkBox = driver.find_element_by_xpath('//input[@aria-label="Select search result"]')
        checkBox.click()
        exportIcon = driver.find_element_by_xpath('//i[@class="icon icon-caret-down"]')
        exportIcon = driver.find_element_by_xpath("//a[contains(text(),'Export')]/child::i")
        exportIcon.click()
        chooseCitation = driver.find_element_by_xpath("//a[contains(text(),'Citation')]").click()
        RISlocate = driver.find_element_by_xpath('//label[@for="download-ris"]/child::input')
        RISlocate.click()
        citationType = driver.find_element_by_xpath('//label[@for="citation-abstract"]/child::input')
        if flag == 0:
            citationType.click()
        exportButton = driver.find_element_by_xpath("//button[contains(text(),'Export')]")
        driver.execute_script("arguments[0].click();", exportButton)
    except:  # 对于各种原因都会出现报错,懒得根据情况一一用程序解决了,直接手动下载吧
        print(filename)
        os.system("pause")


def  not_have_hz(contents):  
    Pattern = re.compile(u'[\u4e00-\u9fa5]+')    
    match = Pattern.search(contents)
    return not match 



path = r"C:\Users\usename\Desktop\\"	#存储论文pdf文件的文件夹的地址,注意最后的两个反斜杠

names = os.listdir(path)

url = "https://ieeexplore.ieee.org/Xplore/home.jsp"
driver = webdriver.Chrome()
driver.get(url)
time.sleep(2)

flag = 0
for filename in names:
    if not_have_hz(filename):
        downloadRIS(filename,flag)

# 由于各种虽然知道原因但不知道解决方法的问题,以及各种不知道原因的问题,下载结果并不一定是所需的,使用时还需要自行检验
driver.quit()
print("引用文件下载完成")
# 浏览器默认下载地址,对于笔者的电脑,RIS格式的默认打开方式为endnote,故直接打开RIS文件即可实现参考文献导入
downloadpath = r'C:\Users\usename\Downloads\\'      # 浏览器默认下载地址
downloadList = os.listdir(downloadpath)
for downloadName in downloadList:
    try:
        os.startfile(downloadpath + downloadName)
        time.sleep(3)
    except:
        print(downloadpath + downloadName)
        os.system("pause")
print("引用添加完成")
print("Missions Complete")

以上是笔者的一些浅见,代码中也可能存在一些漏洞和缺陷,还请大佬们在评论区中或私聊中不吝指出。
如果您对文章中的内容存在疑惑或者需要一些帮助,欢迎评论或私聊。

文章已经同步发布于微信公众号:别玩了来学习。欢迎关注

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Selenium是一个用于自动化浏览器操作的工具,可以通过编写代码来模拟用户在浏览器中的操作。如果你想要使用Selenium批量下载图片,可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Python和Selenium库。你可以使用pip命令来安装Selenium库:`pip install selenium`。 2. 接下来,你需要下载并安装对应浏览器的驱动程序。Selenium需要驱动程序来控制浏览器。不同的浏览器需要不同的驱动程序。例如,如果你使用的是Chrome浏览器,你需要下载ChromeDriver;如果你使用的是Firefox浏览器,你需要下载geckodriver。你可以在Selenium官方网站上找到对应的驱动程序下载链接。 3. 安装完成后,你可以通过以下代码示例来使用Selenium批量下载图片: ```python from selenium import webdriver # 创建一个浏览器实例 driver = webdriver.Chrome() # 如果使用的是Chrome浏览器,需要指定ChromeDriver的路径 # 打开网页 driver.get("http://example.com") # 替换成你要下载图片的网页地址 # 定位图片元素 images = driver.find_elements_by_tag_name("img") # 遍历图片元素并下载图片 for image in images: image_url = image.get_attribute("src") # 下载图片的逻辑,这里可以使用Python的requests库或其他下载图片的方法 # 关闭浏览器 driver.quit() ``` 在上述代码中,我们首先创建了一个浏览器实例,然后打开了指定的网页。接着,通过定位图片元素,我们可以获取到网页中的所有图片。最后,我们可以遍历图片元素,并通过下载图片的逻辑来下载每个图片。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值