我写了下面的代码试图刮取一个谷歌学者页面
import requests as req
from bs4 import BeautifulSoup as soup
url = r'https://scholar.google.com/scholar?hl=en&q=Sustainability and the measurement of wealth: further reflections'
session = req.Session()
content = session.get(url)
html2bs = soup(content.content, 'lxml')
gs_cit = html2bs.select('#gs_cit')
gs_citd = html2bs.find('div', {'id':"gs_citd"})
gs_cit1 = html2bs.find('div', {'id':"gs_cit1"})
但是gs_citd
只给了我这一行<div aria-live="assertive" id="gs_citd"></div>
,并且没有到达它下面的任何级别。同时gs_cit1
返回None
。在
就像出现在这张照片里一样
我想到达突出显示的类,以便能够获取BibTeX引文。在
你能帮忙吗!在
好吧,我想好了。我使用了用于python的selenium模块,它创建了一个虚拟浏览器,允许您执行诸如单击链接和获得结果HTML的输出之类的操作。在解决这个问题时,我遇到了另一个问题,那就是页面必须被加载,否则它只会在弹出的div中返回“Loading…”的内容,所以我使用python时间模块
time.sleep(2)
2秒钟,这样就可以加载内容了。然后,我使用beauthoulsoup解析得到的HTML输出,找到类为“gs_citi”的锚定标记。然后从锚中提取href并将其放入带有“requests”python模块的请求中。最后,我将解码后的响应写入本地文件-学者围兜. 在我在Mac电脑上安装了chromedriver和selenium,使用如下说明: https://gist.github.com/guylaor/3eb9e7ff2ac91b7559625262b8a6dd5f
然后通过python文件签名,允许使用以下说明停止防火墙问题: Add Python to OS X Firewall Options?
以下是我用来生成输出文件的代码“学者围兜“:
希望这能帮助任何人找到解决办法。在
在学者围兜文件:
^{pr2}$相关问题 更多 >
编程相关推荐