谷歌学术搜索文献_谷歌学术论文翻译

谷歌学术搜索文献_谷歌学术论文翻译谷歌学术文献信息爬取及文献下载

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

两个py文件

起主要作用的Search&Download.py

# -*- coding: utf-8 -*-

import requests
from bs4 import BeautifulSoup
from Download import Hubber
import xlwt,os
from time import sleep
from tqdm import tqdm


TotalNum=0
class Article(object):
    title = ""
    article_link = ""
    authors = ""
    authors_link = ""
    abstract = ""
    def __init__(self):
        title = "New Paper"

def save_xls(sheet, paper):
    # 将数据按列存储入excel表格中
    global TotalNum
    sheet.write(TotalNum, 0, TotalNum)
    sheet.write(TotalNum, 1, paper.title)
    sheet.write(TotalNum, 2, paper.article_link)
    sheet.write(TotalNum, 3, paper.journal)
    sheet.write(TotalNum, 4, paper.authors_link)
    sheet.write(TotalNum, 5, paper.abstract)
    TotalNum += 1

head = { \
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36' \
        }  # 20210607更新,防止HTTP403错误
article_titles = []
article_links = []

def GetInfo(sheet,url):
  r = requests.get(url, headers=head)
  r.raise_for_status()
  r.encoding = r.apparent_encoding
  soup = BeautifulSoup(r.text, "html.parser")
  #print("\n"+soup)
  articles = soup.find_all(class_="gs_ri")
  for article in articles:
      paper =Article()
      try:
          title = article.find('h3')
          paper.title = title.text
          #print("\n"+paper.title)
          article_titles.append(paper.title)
          paper.article_link = title.a.get('href')
          #print("\n"+paper.article_link)
          article_links.append(paper.article_link)

          journal = article.find(class_="gs_a")
          paper.journal =journal.text
          #print("\n"+paper.authors)
          authors_addrs = journal.find_all('a')
          for authors_addr in authors_addrs:
              #print("\n"+authors_addr.get('href'))
              paper.authors_link=paper.authors_link +(authors_addr.get('href'))+"\n"

          abstract = article.find(class_="gs_rs")
          paper.abstract = abstract.text
          #print("\n"+paper.abstract)
      except:
          continue
      save_xls(sheet,paper)
  return


def getArticle(article_titles,article_links):
    dir = ".\\Articles\\" +keyword +"\\"
    #print (dir)
    if os.path.exists(dir) == False:
        os.mkdir(dir)
    for k in tqdm(range(len(article_titles))):
        article_titles[k]="{0}".format(article_titles[k].replace(':', ' ')).replace('.', '')
        path = dir + article_titles[k] + ".pdf"
        #print("\n"+path)
        try:
            Hubber.getPDF(article_links[k],path)
            sleep(0.5)
        except:
            continue

if __name__ == '__main__':
    myxls = xlwt.Workbook()
    sheet1 = myxls.add_sheet(u'PaperInfo', True)
    column = ['序号', '文章题目','文章链接','期刊', '作者链接', '摘要']
    for i in range(0, len(column)):
        sheet1.write(TotalNum, i, column[i])
    TotalNum+=1

    keyword=input("keywords is?\n")
    #keyword = diabetes and conjunctiva and (microcirculation or microvasculature)
    #print("\n"+keyword)
    key = keyword.replace(" ","+")
    info = keyword + "_PaperInfo.xls"

    print("\n"+"检索中……")
    if os.path.exists(info) == True:
        print("\n" + "PaperInfo already exists!")
    else:
        start = 0
        for i in tqdm(range(10)):
            url = 'https://xs.dailyheadlines.cc/scholar?start=' + str(start) + '&q=' + key + '&hl=zh-CN&as_sdt=0,5'
            start = start + 10
            GetInfo(sheet1,url)
            myxls.save(keyword+'_PaperInfo.xls')
            sleep(0.5)
    print("\n"+"检索完成")

    print("\n"+"下载中……")
    if len(article_titles) != 0:
        getArticle(article_titles, article_links)
    else:
        import xlrd
        data = xlrd.open_workbook(info)
        table = data.sheet_by_index(0)
        article_titles = table.col_values(1)[1:]
        article_links = table.col_values(2)[1:]
        #print("\n"+article_titles)
        #print("\n"+article_links)
        getArticle(article_titles, article_links)
    print("\n"+ "下载完成")

起辅助作用的Download.py,可将更多网站补充进去! 

import os.path
import re
import requests
from bs4 import BeautifulSoup

class Hubber:
    head = { \
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36' \
        }  # 20210607更新,防止HTTP403错误

    def pdf_hub(url,path):
        try:
            pdf = requests.get(url, headers=Hubber.head)
            with open(path, "wb") as f:
                f.write(pdf.content)
            print("\n"+"pdf found directly!")
        except:
            print("\n"+"failed to download pdf directly!\n" +url)
            Hubber.err_log(url)
    def sci_hub(path,doi):
        doi = str(doi).split("https://doi.org/")[1]
        url = "https://www.sci-hub.ren/doi:" + doi + "#"
        r = requests.get(url, headers=Hubber.head)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        soup = BeautifulSoup(r.text, "html.parser")
        download_url = soup.iframe.attrs["src"]
        try:
            download_r = requests.get(download_url, headers=Hubber.head)
            download_r.raise_for_status()
            with open(path, "wb+") as temp:
                temp.write(download_r.content)
                print("\n"+"Article downloaded by doi!")
        except:
            print("\n"+"failed to download pdf by doi!\n" +url)
            Hubber.err_log(url)

    def err_log(url):
        with open("download_err.txt", "a+", encoding="utf-8") as error:
            error.write("PDF not found,download link may be: \n"+url +"\n")

    def getSoup(url):
        r = requests.get(url, headers=Hubber.head)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        soup = BeautifulSoup(r.text, "html.parser")
        return soup

    def getPDF(url,path):
        if os.path.exists(path) == True:
            print("\n" + "Article already exists")
        else:
            if (len(re.findall('pdf', url)) != 0):
                print ("\n"+'pdf link already!')
                Hubber.pdf_hub(url,path)
            elif re.match("https://www.sci-hub.ren/",url):
                print("\n" + 'sci_hub link!')
                url = str(url).replace("https://www.sci-hub.ren/","https://doi.org/")
                Hubber.sci_hub(path,url)
            #if pdf can be easily found!
            elif re.match("https://academic.oup.com/", url):
                soup = Hubber.getSoup(url)
                pdf_link ="https://academic.oup.com"+soup.find(class_="al-link pdf article-pdfLink").get('href')
                #print("\n"+pdf_link)
                Hubber.pdf_hub(pdf_link,path)
                '''
                doi = soup.select('div[class="ww-citation-primary"]')[0].a.get('href')
                #print("\n"+doi)
                Hubber.sci_hub(path,doi)
                '''
            elif re.match("https://content.iospress.com/", url):
                soup = Hubber.getSoup(url)
                pdf_link = soup.find(class_="btn btn-download btn-right get-pdf").get('href')
                # print("\n"+pdf_link)
                Hubber.pdf_hub(pdf_link, path)
            elif re.match("https://wwwnature.53yu.com/", url):
                soup = Hubber.getSoup(url)
                pdf_link = soup.find(class_="c-pdf-download__link").get('href')
                #print("\n"+pdf_link)
                Hubber.pdf_hub(pdf_link, path)
            elif re.match("https://bjo.bmj.com/", url):
                soup = Hubber.getSoup(url)
                pdf_link = soup.find(class_="article-pdf-download").get('href')
                pdf_link = "https://bjo.bmj.com" + pdf_link
                #print("\n"+pdf_link)
                Hubber.pdf_hub(pdf_link,path)
            elif re.match("https://jamanetwork.com/", url):
                soup = Hubber.getSoup(url)
                pdf_link = soup.find(class_="toolbar-tool toolbar-pdf al-link pdfaccess").get('data-article-url')
                pdf_link = "https://jamanetwork.com" + pdf_link
                #print("\n"+pdf_link)
                Hubber.pdf_hub(pdf_link, path)

            #if pdf can't be easily found,but doi can!
            elif re.match("https://sciencedirect.53yu.com/", url):
                soup = Hubber.getSoup(url)
                doi = soup.find(class_="doi").get('href')
                Hubber.sci_hub(path, doi)
            elif re.match("https://diabetes.diabetesjournals.org/", url):
                soup = Hubber.getSoup(url)
                doi = soup.select('.citation-doi')[0].a.get('href')
                Hubber.sci_hub(path, doi)
            elif re.match("https://journals.lww.com/", url):
                soup = Hubber.getSoup(url)
                doi = "https://doi.org/" + str(soup.find(id="ej-journal-doi").text).split("doi: ")[1]
                Hubber.sci_hub(path, doi)
            else:
                '''
                https://europepmc.org/
                https://iovs.arvojournals.org/
                https://linkspringer.53yu.com/
                '''
                print("\n"+"To be prettified!Download link may be: " +"\n" +url)
                Hubber.err_log(url)

if __name__ == '__main__' :
    url = "https://www.nature.com/articles/s41598-021-87315-7.pdf"
    url1 = "https://www.sci-hub.ren/doi:10.1067/mva.2003.139#"
    url2 = "https://www.sci-hub.ren/doi:10.1067/mva.2003.139#"
    Hubber.getPDF(url,"test.pdf")
    Hubber.getPDF(url1,"test1.pdf")
    Hubber.getPDF(url2,"test2.pdf")

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/183156.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 前缀和与差分数组[通俗易懂]

    前缀和与差分数组[通俗易懂]文章目录适合解决的问题差分数组的定义解释借教室(二分加差分数组)适合解决的问题例:n个数,m次操作。每一次操作都给定区间和数值[l,r]+del.最后有q个询问,问[l,r]点的值或者单点查值。注:先进行m个修改操作,后进行查询操作。(离线的区间区间修改问题)差分数组的定义记录当前位置与上一位置数的差值解释原数组a[5]=9,3,5,4,2差分数组b[5]=9,-6,2,…

  • 解决 bcm43问题

    解决 bcm43问题

  • 群晖服务器名修改,闻上云刷黑群晖后免拆机修改序列号和mac地址

    群晖服务器名修改,闻上云刷黑群晖后免拆机修改序列号和mac地址闻上云刷黑群晖后免拆机修改序列号和mac地址2020-02-2715:03:1713点赞98收藏65评论最近,矿渣论坛的u盘直刷黑群晖固件免费了,再也不用辛辛苦苦的攒渣金了!值此利好消息,帮同事先后购入2台闻上云原封机器,都是原始系统。到手后成色很好,价格也从原来的150包邮一路涨到现在的300+了。这台机器颜值好,做工有大厂风范,甩蜗牛、魔盒之类矿渣几条街。。。这里放下xxx大佬的群晖引导固件…

  • mysql有多少个端口号_mysql默认端口号(mysql端口号是多少)[通俗易懂]

    mysql默认端口号(mysql端口号是多少)2020-05-0722:14:36共10个回答mysql的默认端口号是多少mysql默认端口号为3306,修改端口号方法:修改配置文件/etc/my.cnfmysql使用的默认端口号是哪个端口mysql的默认端口是3306,可以编辑用户目录下的.my.cnf文件进行修改.sqlserver默认端口号为:1433oracle默认端口号为:1521DB…

  • MySQL 分库分表,写得太好了!

    https://www.toutiao.com/a6603492496779510276/?tt_from=mobile_qq&utm_campaign=client_share&timestamp=1549497188&app=news_article&utm_source=mobile_qq&iid=59568063679&utm_medium=…

  • pycharm简单案例代码_python简单代码编写

    pycharm简单案例代码_python简单代码编写由于纠结良久,因为不知道从什么地方开始说起。想了想,还是实用主义,主要是教大家用软件编程,所以pycharm的一些功能介绍什么的,大家后续可以自己摸索。毕竟如果专门讲解pycharm的功能,那这篇帖子就完全将pycharm了,没必要。我们的目标是,先学会基本的语言与python编程。好的,不说废话,进入正题!######################首先,我们使用pycharm编程,就需要先创建…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号