pycurl 使用 跳转
来源:互联网 发布:linux rpm安装java 编辑:程序博客网 时间:2024/06/14 20:54
pycurl 使用 跳转
根据doi获取文献的最终url,而不获得原文(如想获得全文,可以修改 FOLLOWLOCATION为1)
doi='10.1007/s12559-015-9328-x'storage = io.BytesIO() # python3, python2与此处不同,存储字符串c = pycurl.Curl() # 初始化对象c.setopt(c.URL, 'http://dx.doi.org/'+doi) # 设置urlc.setopt(pycurl.FOLLOWLOCATION, 0) #是否重定向到url,0表示关闭重定向,1表示开启重定向# c.setopt(c.HTTPHEADER,["Accept: application/vnd.crossref.unixsd+xml"]) #设置headerc.setopt(pycurl.WRITEFUNCTION, storage.write)# 将返回的字符串写入storage# c.setopt(pycurl.HEADERFUNCTION, storage.write)# 将返回的header写入storagec.perform() # 执行# out = c.getinfo(pycurl.EFFECTIVE_URL)# 获取最新的url,如果重定向,则返回跳转后的urlcontent = storage.getvalue().decode('utf-8')#返回byte,需要进行decode,如果 c.setopt(pycurl.FOLLOWLOCATION, 1)设置为1,则返回跳转后的全文 #返回数据进行正则表达式匹配,获取重定向urlout = re.compile('(?<=href=").*(?=">)').findall(content)[0]cu_w.execute('insert into doi_link values(%s, %s, %s)', (pmid,doi, out))con.commit()c.close()storage.close()
1 0
- pycurl 使用 跳转
- 使用pycurl上传文件
- python pycurl 使用
- PycURL库使用
- python3使用pycurl库
- PycURL
- pycurl
- python-pycurl库的使用
- 使用pycurl进行web提交
- python使用pycurl模块详解
- python使用pycurl模块详解
- pycurl和requests使用感受
- python使用pycurl模块详解
- 多线程使用pycurl时出现段错误(segmentation fault)
- 使用pycurl获取http请求的content-length
- 在Ubuntu 14.04 64bit上使用pycURL模块示例
- windows10下使用pyopenssl, pycurl 访问https网站(python)
- linux使用yum更新下载时报错PYCURL ERROR 56
- js DOM节点的创建、插入、删除、查找、替换例子
- iOS新浪微博 微信好友、微信朋友圈、QQ自身sdk分享方法
- c语言中的static
- iOS优秀博客收录
- linux select 多路复用机制
- pycurl 使用 跳转
- MXNet和caffe、theano的关系
- error C2065: “SurfFeatureDetector”: 未声明的标识符
- 使用System.arraycopy()实现数组之间的复制
- md5解密网站大全
- [环境搭建] Android SDK下载和更新失败的解决方法!!!
- Android46_摄像头
- The Genymotion virtual device could not obtain an IP address
- iOS -字符串替换 富文本的简单使用