前言
有的时候需要进行大批量的文献搜索,动则几百篇。但是只在web of science上面一篇一篇读,又很慢。手动copy页面到word里面,也是很低效。因此考虑利用python来对web of science上的文献进行批量搜集。
需求:
在web of science进行文献搜索后,希望把重要信息(如标题、作者、期刊名、日期、摘要)记录下来。
步骤:
1. 输入关键词搜索文献
2. 点击【导出】,然后选择自己想要导出的文献的数目,也就是标号。格式选择【html格式】
3. 打开html,查看它的源码。可以清楚的看到html的结构,其中【标题】、【作者】、【日期】、【摘要】等信息都包含在每一个<tr>当中,因此用Python可以很好的提取出当中的内容。
例如,AB对应的就是Abstract,AU对应的就是作者,TI对应的就是title,PD对应的是日期等等。
4. 下面考虑用python实现相应信息的提取,代码如下:
from bs4 import BeautifulSoup
import pandas as pd
path = 'C:/Users/Xin/Desktop/pach/savedrecs-2.html'
htmlfile = open(path, 'r', encoding='utf-8')
htmlhandle = htmlfile.read()
soup = BeautifulSoup(htmlhandle, 'lxml')
txtfile = open('test.txt','w',encoding='utf-8')
rt = soup.find_all('td')
Title = ""
Journal = ""
Author = ""
Abstract = ""
Date = ""
flag = 0
# title
for n in range(0,rt.__len__()):
if flag ==0:
if rt[n].get_text() == 'TI ':
Title = rt[n+1].get_text().replace("\n ", "")
continue
if rt[n].get_text() == 'PD ':
Date = rt[n + 1].get_text().replace("\n ", "")
continue
if rt[n].get_text() == 'SO ':
Journal = rt[n + 1].get_text()
continue
if rt[n].get_text() == 'AU ':
Author = rt[n + 1].get_text().replace("\n ", "")
continue
if rt[n].get_text() == 'AB ':
Abstract = rt[n+1].get_text().replace("\n ", "")
flag = 1
continue
if flag == 1:
t_info = "标题"+ Title +"标题" + "\n" + "作者"+ Author + "作者"+"\n" + "杂志"+Journal + "杂志" +"\n" + "日期"+Date + "日期"+"\n"+ "摘要"+Abstract + "摘要"+"\n"
txtfile.write(t_info)
flag = 0
txtfile.close()
在这里,用到了两个包,分别是beautifulsoup和pandas,相关的使用方法可以自行搜索一下,不是本篇文章的重点。
5. 最终结果如下所示:
![txt文本内容](https://i-blog.csdnimg.cn/blog_migrate/e7eb04b4e846d4098516c4c9f15f0290.png)
![](https://i-blog.csdnimg.cn/blog_migrate/73472e8aef9130755582e4d029e6eae4.png)