Python 值错误:在Google Scholar中解析数据时读取关闭的文件

Python 值错误:在Google Scholar中解析数据时读取关闭的文件,python,web-scraping,jupyter,google-scholar,Python,Web Scraping,Jupyter,Google Scholar,我是一名学习生物的非cs学生,但我研究python数据科学的目的是为了让Google Scholar成为一名网络垃圾。我创建了一个最初可以工作的程序,但不知何故它随机停止工作,并给了我一个值错误。我认为这可能与谷歌严格要求机器人搜索他们的网站有关。任何建议和补救措施都会有帮助!我正在使用Jupyter笔记本ipython和Python3 代码: import pip def install(package): pip.main(['install', package]) ins

我是一名学习生物的非cs学生,但我研究python数据科学的目的是为了让Google Scholar成为一名网络垃圾。我创建了一个最初可以工作的程序,但不知何故它随机停止工作,并给了我一个值错误。我认为这可能与谷歌严格要求机器人搜索他们的网站有关。任何建议和补救措施都会有帮助!我正在使用Jupyter笔记本ipython和Python3

代码:

import pip    
def install(package):
    pip.main(['install', package])

install('BeautifulSoup4')

from bs4 import BeautifulSoup
import urllib.request
from urllib.request import FancyURLopener

class AppURLopener(urllib.request.FancyURLopener):
    version = "Mozilla/5.0"

def page_citations(x):
    #number of pages of google searches that you want to run

    query = input()
    query = str(query)
    opener = AppURLopener()
    m = 0
    q = 0
    l = make_array()
    while m < x:
        response = 
        opener.open('https://scholar.google.com/scholar?
        start='+str(q)+'&q=' + query + '&hl=en&as_sdt=0,5').read()
        soup = BeautifulSoup(response, 'html.parser')
        for word in str(soup.find_all(class_ = "gs_fl")).split():
            if word.endswith(''+ '</a>'): 
                l = np.append(l, word.strip('</a>'))
        q = q + 10
        m = m + 1
    n = make_array()

    for number in l:
        try:
            number = int(number)
            n = np.append(n, number)
        except: continue

    return n
导入pip
def安装(软件包):
main(['install',package])
安装('BeautifulSoup4')
从bs4导入BeautifulSoup
导入urllib.request
从urllib.request导入FancyURLopener
类AppURLopener(urllib.request.FancyURLopener):
version=“Mozilla/5.0”
def页面_引用(x):
#要运行的google搜索页面数
查询=输入()
query=str(查询)
opener=AppURLopener()
m=0
q=0
l=生成数组()
当m
错误:
ValueError:读取关闭的文件

引发错误的代码行是哪一行?在opener.open()?抛出错误的代码行是哪一行?在opener.open()处?