码迷,mamicode.com
首页 > 其他好文 > 详细

SAE 部署 bilibili 爬虫

时间:2018-04-17 17:00:46      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:https   img   sina   head   没有   htm   容器云   共享   上传   

layout: post
title: sae部署bilibili爬虫
categories: python
tags: spider sae

前端效果

技术分享图片

sae准备工作

从本地上传的爬虫到sae一直被提示没有requests模块,在requirements.txt里声明了也不行。起初我以为是这个第三方包被屏蔽了,直到看到sae支持中心-Python共享服务器-运行环境才直到原因:requirements.txt 只在容器云app里面才会生效,同理 runtime.txt 也是。因此需要在共享服务器上面使用第三方包的话,只能自己上传。我通过 ubantu python 2.7.6 使用pip install -t vendor requests安装上 requests 包,再将这个文件夹上传到 sae 根目录就可以使用了。因为涉及到我自己账号的 cookie,这里我使用的是码云私有仓库保存我的代码,不再贴出。

bilibili-Getcoin

B站只要登录一下就可以获得当日的一硬币,在爬虫界这算是非常简单的了。我之前尝试用国外的某ae来爬B站,得到503错误(403?),国外访问B站是要梯子的。
code:

# -*- coding: utf-8 -*-
"""
requests学习实战
"""
import requests
url = 'https://account.bilibili.com/site/getCoin'

headers = {}
cookies = {}
with requests.Session() as s:
r = s.get(url,headers=headers,cookies=cookies)
print r.status_code
bjson = r.json()
#print bjson.keys()
print bjson[u'data'] 

print 'over!'

以上。

SAE 部署 bilibili 爬虫

标签:https   img   sina   head   没有   htm   容器云   共享   上传   

原文地址:https://www.cnblogs.com/aubucuo/p/spider6.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!