Skip to content

bangumi cine插件 内置函数(通用)

zhengfan2014 edited this page Jun 14, 2020 · 1 revision

⚙️ 内置函数

get_html()

描述:

get_html() 函数和requests.get函数相同,但是get_html() 函数返回url的网页源代码同时会缓存一份在本地,两分钟内的相同请求直接调用缓存的结果,减少向服务器请求的次数,降低被网站站长察觉的几率

语法:

get_html(url)

参数:

参数 说明
url 字符串(str),必填参数,为要访问的url bangumi/cine beta 0.1.0+支持
ua 字符串(str),可选参数,不填默认为pc的ua。 bangumi/cine beta 0.1.0+支持
cf 整数(int),可选参数,cf=1时启用绕过cloudflare 5秒盾功能。不填默认不启用 bangumi/cine beta 0.1.0+支持
mode 字符串(str),可选参数,默认为mode='html'输出网页源代码,当mode='url'时,返回的不是网页源代码而是request请求后的url。适合对付那些需要302跳转才能获取真实视频地址的 bangumi/cine beta 0.1.0+支持
encode 字符串(str),可选参数,用来指定网页编码,默认为utf-8,当输出为乱码时可尝试指定encode='gbk' bangumi/cine beta 0.2.0+支持

ua可传入的值:

说明
pc 电脑的ua 默认
mobile 安卓手机的ua
iphone 苹果手机的ua
ipad ipad的ua
mac 苹果电脑的ua

mode可传入的值:

说明
html 输出网页源代码 默认
url 输出request请求后跳转到的url

encode可传入的值:

说明
utf-8 使用utf-8来解码html源代码 默认
gbk 使用gbk来解码html源代码

返回值:

函数返回url的网页源代码

实例:

以下展示了使用 get_html() 方法的实例:

print(get_html('http://google.cn'))

以上实例运行后输出结果为:

<!DOCTYPE html>
<html lang="zh">
  <meta charset="utf-8">
  <title>Google</title>
  <style>
    html { background: #fff; margin: 0 1em; }
    body { font: .8125em/1.5 arial, sans-serif; text-align: center; }
    h1 { font-size: 1.5em; font-weight: normal; margin: 1em 0 0; }
    p#footer { color: #767676; font-size: .77em; }
    p#footer a { background: url(//www.google.cn/intl/zh-CN_cn/images/cn_icp.gif) top right no-repeat; padding: 5px 20px 5px 0; }
    ul { margin: 2em; padding: 0; }
    li { display: inline; padding: 0 2em; }
    div { -moz-border-radius: 20px; -webkit-border-radius: 20px; border: 1px solid #ccc; border-radius: 20px; margin: 2em auto 1em; max-width: 650px; min-width: 544px; }
    div:hover, div:hover * { cursor: pointer; }
    div:hover { border-color: #999; }
    div p { margin: .5em 0 1.5em; }
    img { border: 0; }
  </style>
  <div>
    <a href="http://www.google.com.hk/webhp?hl=zh-CN&amp;sourceid=cnhp">
      <img src="//www.google.cn/landing/cnexp/google-search.png" alt="Google" width="586" height="257">
    </a>
    <h1><a href="http://www.google.com.hk/webhp?hl=zh-CN&amp;sourceid=cnhp"><strong id="target">google.com.hk</strong></a></h1>
    <p>请收藏我们的网址
  </div>
  <ul>
    <li><a href="http://translate.google.cn/?sourceid=cnhp">翻译</a>
  </ul>
  <p id="footer">&copy;2011 - <a href="http://www.miibeian.gov.cn/">ICP证合字B2-20070004号</a>
  <script nonce="seq4yqrbKQbF7TNEBaEOtg">
    var gcn=gcn||{};gcn.IS_IMAGES=(/images\.google\.cn/.exec(window.location)||window.location.hash=='#images'||window.location.hash=='images');gcn.HOMEPAGE_DEST='http://www.google.com.hk/webhp?hl=zh-CN&sourceid=cnhp';gcn.IMAGES_DEST='http://images.google.com.hk/imghp?'+'hl=zh-CN&sourceid=cnhp';gcn.DEST_URL=gcn.IS_IMAGES?gcn.IMAGES_DEST:gcn.HOMEPAGE_DEST;gcn.READABLE_HOMEPAGE_URL='google.com.hk';gcn.READABLE_IMAGES_URL='images.google.com.hk';gcn.redirectIfLocationHasQueryParams=function(){if(window.location.search&&/google\.cn/.exec(window.location)&&!/webhp/.exec(window.location)){window.location=String(window.location).replace('google.cn','google.com.hk')}}();gcn.replaceHrefsWithImagesUrl=function(){if(gcn.IS_IMAGES){var a=document.getElementsByTagName('a');for(var i=0,len=a.length;i<len;i++){if(a[i].href==gcn.HOMEPAGE_DEST){a[i].href=gcn.IMAGES_DEST}}}}();gcn.listen=function(a,e,b){if(a.addEventListener){a.addEventListener(e,b,false)}else if(a.attachEvent){var r=a.attachEvent('on'+e,b);return r}};gcn.stopDefaultAndProp=function(e){if(e&&e.preventDefault){e.preventDefault()}else if(window.event&&window.event.returnValue){window.eventReturnValue=false;return false}if(e&&e.stopPropagation){e.stopPropagation()}else if(window.event&&window.event.cancelBubble){window.event.cancelBubble=true;return false}};gcn.resetChildElements=function(a){var b=a.childNodes;for(var i=0,len=b.length;i<len;i++){gcn.listen(b[i],'click',gcn.stopDefaultAndProp)}};gcn.redirect=function(){window.location=gcn.DEST_URL};gcn.setInnerHtmlInEl=function(a){if(gcn.IS_IMAGES){var b=document.getElementById(a);if(b){b.innerHTML=b.innerHTML.replace(gcn.READABLE_HOMEPAGE_URL,gcn.READABLE_IMAGES_URL)}}};
    gcn.listen(document, 'click', gcn.redirect);
    gcn.setInnerHtmlInEl('target');
  </script>

post_html()

描述:

post_html() 函数和requests.post函数相同,但是post_html() 函数返回url的网页源代码同时会缓存一份在本地,两分钟内的相同请求直接调用缓存的结果,减少向服务器请求的次数,降低被网站站长察觉的几率

语法:

post_html(url,data)

参数:

参数 说明
url 字符串(str),必填参数,为要访问的url bangumi/cine beta 0.1.0+支持
data 字符串化的字典(str(dict)),必填参数,为要post的值组成的字典 bangumi/cine beta 0.1.0+支持
ua 字符串(str),可选参数,不填默认为pc的ua。 bangumi/cine beta 0.1.0+支持
encode 字符串(str),可选参数,用来指定网页编码,默认为utf-8,当输出为乱码时可尝试指定encode='gbk' bangumi/cine beta 0.2.0+支持

ua可传入的值:

说明
pc 电脑的ua
mobile 安卓手机的ua
iphone 苹果手机的ua
ipad ipad的ua
mac 苹果电脑的ua

encode可传入的值:

说明
utf-8 使用utf-8来解码html源代码 默认
gbk 使用gbk来解码html源代码

返回值:

函数返回url的网页源代码

实例:

以下展示了使用 post_html() 方法的实例:

payload = str({'key1': 'value1', 'key2': 'value2'})

print(post_html('https://httpbin.org/post',payload))

以上实例运行后输出结果为:

"form": {
    "key2": "value2",
    "key1": "value1"
  },

unix_to_data()

描述:

unix_to_data()返回人类能正常理解的unix时间

语法:

unix_to_data(uptime,format)

参数:

参数 说明
uptime 整数(int),必填参数,为要转换的unix时间(10位或者13位)
format 字符串(str),可选参数,不填默认输出 2020-10-10格式的时间。

format可传入的值:

format值 说明
data 输出 2020-10-10格式的时间
zhdata 输出 2020年10月10日 格式的时间
datatime 输出 2020-10-10 10:10:10 格式的时间
zhdatatime 输出 2020年10月10日 10时10分10秒 格式的时间
time 输出 10:10:10 格式的时间
zhtime 输出 10时10分10秒 格式的时间

返回值:

函数返回人类能正常理解的unix时间

实例:

以下展示了使用 unix_to_data() 方法的实例:

print(unix_to_data(1588590928))

以上实例运行后输出结果为:

2020-5-4
Clone this wiki locally