别找了,小程序实现isbn扫码获取图书信息2024最新可用(保姆级教程内附接口)(2)

在这里插入图片描述


提示:以下是本篇文章正文内容,介绍如何抓取某瓣的接口,由于版权原因,分析直接跳过

一、开始抓某网站isbn接口(由于版权原因,分析直接跳过)

由于版权原因,分析直接跳过

由于版权原因,分析直接跳过

二、某接口最新可用Tp5代码

1.后端部署代码

//图书接口测试
  public function getBookInfo()
    {
        $isbn = $\_GET['isbn'];
        try {
            $surl = 'https://book.douban.com/isbn/' . $isbn . '/';
            $headers = json\_encode(get\_headers($surl), true);
            $headers = json\_encode($headers, true);
            $surl = $this->cut($headers, 'Location: ', '"');
            $surl = str\_replace('\\', '', $surl);//302地址
            $data = $this->getIsbn($surl);
            $data\_1 = $this->cut($data, 'application/ld+json">', '</script>');
            $data\_1 = json\_decode($data\_1, true);
            $res['title'] = $data\_1['name'];//书名

            $res['logo'] = $this->cut($data, 'data-pic="', '"');//图标

            $author = $data\_1['author'];
            if (!isset($author[0]) || $author[0] == '') {
                $author[0]['name'] = '未知';
            }
            $res['author'] = $author;//作者
            //相关书籍推荐
            $publisher = $this->cut($data, '出版社:</span>', '<br/>');
            if ($publisher == '') {
                $publisher = '未知';
            }
            $res['publisher'] = $publisher;//出版社

            $author\_desc = $this->cut($data, 'class="indent ">', '</div>');
            $res['author\_desc'] = $this->cut($author\_desc, '<p>', '</p>');
            if ($res['author\_desc'] == "") {
                $res['author\_desc'] = '未知';
            }
            $res['author\_desc'] = $author\_desc;//作者简介
            $published = $this->cut($data, '出版年:</span>', '<br/>');
            if ($published == '') {
                $published = '未知';
            }
            $res['published'] = $published;//出版年

            $page = $this->cut($data, '页数:</span>', '<br/>');
            if ($page == '') {
                $page = '未知';
            }
            $res['page'] = $page;//页数

            $price = $this->cut($data, '定价:</span>', '<br/>');
            if ($price == '') {
                $price = '未知';
            }
            $res['price'] = $price;//定价
            $designed = $this->cut($data, '装帧:</span>', '<br/>');
            if ($designed == '') {
                $designed = '未知';
            }
            $res['designed'] = $designed;//装帧

            $description = $this->cut($data, 'class="intro">', '</p>');
            if ($description == '') {
                $description = '未进行描述';
            } else {
                $description = explode('<p>', $description)[1];
            }
            $res['description'] = $description;//简介
            // return\_msg(200, '请求成功', $res);
            return json($res);
        } catch (Exception $e) {
            return\_msg(500, '服务器内部错误', $e);
        }


    }

    private function cut($content, $start, $end)
    {
        $r = explode($start, $content);
        if (isset($r[1])) {
            $r = explode($end, $r[1]);
            return $r[0];
        }
        return '';
    }

    private function getIsbn($url) //curl get请求
    {
        $postUrl = $url;
        $curlPost = 'GET';
        $curl = curl\_init();//初始化curl
        curl\_setopt($curl, CURLOPT\_URL, $postUrl);//抓取指定网页
        curl\_setopt($curl, CURLOPT\_HEADER, 0);//设置header
        curl\_setopt($curl, CURLOPT\_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl\_setopt($curl, CURLOPT\_POST, 1);//post提交方式
        curl\_setopt($curl, CURLOPT\_POSTFIELDS, $curlPost);
        curl\_setopt($curl, CURLOPT\_SSL\_VERIFYPEER, false); //不验证证书下同
        curl\_setopt($curl, CURLOPT\_SSL\_VERIFYHOST, false);
        $data = curl\_exec($curl);//运行curl
        curl\_close($curl);
        return $data;
    }

2.使用方法

访问:https://你的域名/Index/Api/getBookInfo?isbn=97****96898

上面的是我的目录结构,具体自己放在哪,改一下即可!!
然后看一下运行结果:
在这里插入图片描述

ok,没问题,有一点不足,就是会吃内存资源,如果只是需要对数据库中的isbn做一次采集,可以用python加一个代理池即可(频繁访问会被拉黑!)


三、对接小程序实现扫码获取图书详情!

1.预览

在这里插入图片描述

2.代码介绍

通过wxml中点击scanCode的方法

 <view class="cu-form-group">
<button type="primary" bindtap="scanCode">一键扫描识别</button>
    </view>

来到js方法中:

scanCode: function (event) {
    console.log(1)
    let that=this;
      // 允许从相机和相册扫码
      wx.scanCode({
       onlyFromCamera:true,
       scanType:['barCode'],
       success:res=>{
         console.log(res.result)
         that.get\_isbn(res.result);
       },
       fail:err=>{
         console.log(err);
       }
      })
      },

微信提供 wx.scanCode接口调用即可获取扫码信息,下图是控制台输出的结果
在这里插入图片描述
获取到后调用方法get_isbn()

 that.get\_isbn(res.result);

最后对刚刚的接口做一次requests访问请求,写入AppData即可

      get\_isbn:function(ee){
          let that=this;
        wx.request({
            url: 'https://你的域名/Index/Api/getBookInfo', //仅为示例,并非真实的接口地址
            data: {
            isbn:ee
            },
            header: {
            'content-type': 'application/json' // 默认值
            },
            success (res) {
            console.log(res.data)
            that.setData({
                tp_list:res.data
            })
            }
            })
      },

2.完整Wxml代码

<cu-custom bgColor="bgmain" isBack="{{true}}">
    <view slot="content">发布</view>
</cu-custom>
<view class="weui-cells weui-cells\_after-title page">
    <view class="box">
        <view class="cu-bar bg-white">
            <view class="info">
                <text class="cuIcon-titles text-green"></text>
                <text class="text-xl text-bold">商品基本信息</text>
            </view>
        </view>
    </view>
    <view class="cu-form-group">
<button type="primary" bindtap="scanCode">一键扫描识别</button>
    </view>
    <view class="cu-form-group">
        <view class="title">商品名称</view>
        <input bindinput="bookNameInput" placeholder="请输入商品的名称" value="{{tp\_list.title}}"></input>
    </view>
    <view class="weui-cell weui-cell\_input">
        <view class="weui-cell\_\_hd">
            <view class="weui-label">添加图片</view>
        </view>
    </view>
    <view class="margin-left" >
        <image style="width: 200rpx; height: 200rpx; background-color: #eeeeee;"  src="{{tp\_list.logo}}"></image>
    </view>
    <view class="cu-form-group">
        <view class="title">新旧程度</view>
        <picker bindchange="bindPickerChange" range="{{array}}" value="{{index}}">
            <view class="picker">
            {{array[index]}}
          </view>
        </picker>
    </view>
    <view class="cu-form-group">
        <view class="title">所属分类</view>
        <picker bindchange="bindPickerChanges" range="{{cateList}}" rangeKey="{{'name'}}" value="{{cateList[indexs].id}}">
            <view class="picker">
            {{cateList[indexs].name}}
          </view>
        </picker>
    </view>
    <view class="cu-form-group">
        <view class="title">原价</view>
        <input bindinput="oldpriceInput" name="oldPrice" placeholder="最多保留两位小数" type="digit" value="{{tp\_list.price}}"></input>
    </view>
    <view class="cu-form-group">
        <view class="title">二手价</view>
        <input bindinput="newpriceInput" name="newPrice" placeholder="最多保留两位小数" type="digit"></input>
    </view>
    <view class="cu-form-group">
        <view class="title">联系电话</view>
        <input bindinput="phone" name="phone" placeholder="请输入电话" type="number"></input>
    </view>

    <view class="cu-form-group margin-bottom">
        <view class="title">具体描述</view>
        <textarea autoHeight="true" bindinput="descInput" disabled="{{modalName!=null}}" maxlength="-1" placeholder="请输入描述" value="{{tp\_list.description}}"></textarea>
    </view>

    <!-- <view class="del\_remark text-sm margin-left margin-bottom">\*长按图片可进行删除</view> -->
    <button bindtap="save" class="my\_button" type="primary">发布</button>
</view>


3.完整js代码

  scanCode: function (event) {
    console.log(1)
    let that=this;
      // 允许从相机和相册扫码
      wx.scanCode({
       onlyFromCamera:true,
       scanType:['barCode'],
       success:res=>{
         console.log(res.result)
         that.get\_isbn(res.result);
       },
       fail:err=>{
         console.log(err);
       }
      })
      },
      get\_isbn:function(ee){
          let that=this;
        wx.request({
            url: 'https://域名/Index/Api/getBookInfo', //仅为示例,并非真实的接口地址
            data: {
            isbn:ee
            },
            header: {
            'content-type': 'application/json' // 默认值
            },
            success (res) {
            console.log(res.data)
            that.setData({
                tp_list:res.data
            })
            }
            })
      },

4.完整wxss代码

page {
  line-height: 1.6;
  font-family: -apple-system-font,Helvetica Neue,sans-serif;
}

.cu-bar .action:first-child {
  background-color: #ff6444;
  color: #fff;
}

.info {
  background: #fff;
  color: #000;
}

.bgmain {
  background-color: #ff6444;
  color: #fff;
}

icon {
  vertical-align: middle;
}

.weui-cells {
  position: relative;
  margin-top: 1.17647059em;
  background-color: #fff;
  line-height: 1.41176471;
  font-size: 17px;
}

.weui-cells:before {
  border-top: 1rpx solid #d9d9d9;
}

.weui-cells:after,.weui-cells:before {
  content: " ";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  color: #d9d9d9;
}

.weui-cells:after {
  border-bottom: 1rpx solid #d9d9d9;
}

.weui-cells__title {
  margin-top: .77em;
  margin-bottom: .3em;
  padding-left: 15px;
  padding-right: 15px;
  color: #999;
  font-size: 14px;
}

.weui-cells_after-title {
  margin-top: 0;
}

.weui-cells__tips {
  margin-top: .3em;
  color: #999;
  padding-left: 15px;
  padding-right: 15px;
  font-size: 14px;
}

.weui-cell {
  padding: 10px 15px;
  position: relative;
  display: flex;
  -webkit-box-align: center;
  align-items: center;
}

.weui-cell:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  border-top: 1rpx solid #d9d9d9;
  color: #d9d9d9;
  left: 15px;
}

.weui-cell:first-child:before {
  display: none;
}

.weui-cell_active {
  background-color: #ececec;
}

.weui-cell_primary {
  -webkit-box-align: start;
  align-items: flex-start;
}

.weui-cell__bd {
  -webkit-box-flex: 1;
  flex: 1;
}

.weui-cell__ft {
  text-align: right;
  color: #999;
}

.weui-cell_access {
  color: inherit;
}

.weui-cell__ft_in-access {
  padding-right: 13px;
  position: relative;
}

.weui-cell__ft_in-access:after {
  content: " ";
  display: inline-block;
  height: 6px;
  width: 6px;
  border-color: #c8c8cd;
  border-style: solid;
  border-width: 2px 2px 0 0;
  transform: matrix(.71,.71,-.71,.71,0,0);
  position: relative;
  top: -2px;
  position: absolute;
  top: 50%;
  margin-top: -4px;
  right: 2px;
}

.weui-cell_link {
  color: #586c94;
  font-size: 14px;
}

.weui-cell_link:active {
  background-color: #ececec;
}

.weui-cell_link:first-child:before {
  display: block;
}

.weui-icon-radio {
  margin-left: 3.2px;
  margin-right: 3.2px;
}

.weui-icon-checkbox_circle,.weui-icon-checkbox_success {
  margin-left: 4.6px;
  margin-right: 4.6px;
}

.weui-check__label:active {
  background-color: #ececec;
}

.weui-check {
  position: absolute;
  left: -9999px;
}

.weui-check__hd_in-checkbox {
  padding-right: .35em;
}

.weui-cell__ft_in-radio {
  padding-left: .35em;
}

.weui-cell_input {
  padding-top: 0;
  padding-bottom: 0;
}

.weui-label {
  width: 105px;
  word-wrap: break-word;
  word-break: break-all;
}

.weui-input {
  height: 2.58823529em;
  min-height: 2.58823529em;
  line-height: 2.58823529em;
}

.weui-toptips {
  position: fixed;
  transform: translateZ(0);
  top: 0;
  left: 0;
  right: 0;
  padding: 5px;
  font-size: 14px;
  text-align: center;
  color: #fff;
  z-index: 5000;
  word-wrap: break-word;
  word-break: break-all;
}

.weui-toptips_warn {
  background-color: #e64340;
}

.weui-textarea {
  display: block;
  width: 100%;
}

.weui-textarea-counter {
  color: #b2b2b2;
  text-align: right;
}

.weui-cell_warn,.weui-textarea-counter_warn {
  color: #e64340;
}

.weui-form-preview {
  position: relative;
  background-color: #fff;
}

.weui-form-preview:before {
  top: 0;
  border-top: 1rpx solid #d9d9d9;
}

.weui-form-preview:after,.weui-form-preview:before {
  content: " ";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  color: #d9d9d9;
}

.weui-form-preview:after {
  bottom: 0;
  border-bottom: 1rpx solid #d9d9d9;
}

.weui-form-preview__value {
  font-size: 14px;
}

.weui-form-preview__value_in-hd {
  font-size: 26px;
}

.weui-form-preview__hd {
  position: relative;
  padding: 10px 15px;
  text-align: right;
  line-height: 2.5em;
}

.weui-form-preview__hd:after {
  content: " ";
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 1px;
  border-bottom: 1rpx solid #d9d9d9;
  color: #d9d9d9;
  left: 15px;
}

.weui-form-preview__bd {
  padding: 10px 15px;
  font-size: .9em;
  text-align: right;
  color: #999;
  line-height: 2;
}

.weui-form-preview__ft {
  position: relative;
  line-height: 50px;
  display: flex;
}

.weui-form-preview__ft:after {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  border-top: 1rpx solid #d5d5d6;
  color: #d5d5d6;
}

.weui-form-preview__item {
  overflow: hidden;
}

.weui-form-preview__label {
  float: left;
  margin-right: 1em;
  min-width: 4em;
  color: #999;
  text-align: justify;
  text-align-last: justify;
}

.weui-form-preview__value {
  display: block;
  overflow: hidden;
  word-break: normal;
  word-wrap: break-word;
}

.weui-form-preview__btn {
  position: relative;
  display: block;
  -webkit-box-flex: 1;
  flex: 1;
  color: #3cc51f;
  text-align: center;
}

.weui-form-preview__btn:after {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  bottom: 0;
  border-left: 1rpx solid #d5d5d6;
  color: #d5d5d6;
}

.weui-form-preview__btn:first-child:after {
  display: none;
}

.weui-form-preview__btn_active {
  background-color: #eee;
}

.weui-form-preview__btn_default {
  color: #999;
}

.weui-form-preview__btn_primary {
  color: #0bb20c;
}

.weui-cell_select {
  padding: 0;
}

.weui-select {
  position: relative;
  padding-left: 15px;
  padding-right: 30px;
  height: 2.58823529em;
  min-height: 2.58823529em;
  line-height: 2.58823529em;
  border-right: 1rpx solid #d9d9d9;
}

.weui-select:before {
  content: " ";
  display: inline-block;
  height: 6px;
  width: 6px;
  border-color: #c8c8cd;
  border-style: solid;
  border-width: 2px 2px 0 0;
  transform: matrix(.71,.71,-.71,.71,0,0);
  position: relative;
  top: -2px;
  position: absolute;
  top: 50%;
  right: 15px;
  margin-top: -4px;
}

.weui-select_in-select-after {
  padding-left: 0;
}

.weui-cell__bd_in-select-before,.weui-cell__hd_in-select-after {
  padding-left: 15px;
}

.weui-cell_vcode {
  padding-right: 0;
}

.weui-vcode-btn,.weui-vcode-img {
  margin-left: 5px;
  height: 2.58823529em;
  vertical-align: middle;
}

.weui-vcode-btn {
  display: inline-block;
  padding: 0 .6em 0 .7em;
  border-left: 1px solid #e5e5e5;
  line-height: 2.58823529em;
  font-size: 17px;
  color: #3cc51f;
  white-space: nowrap;
}

.weui-vcode-btn:active {
  color: #52a341;
}

.weui-cell_switch {
  padding-top: 6px;
  padding-bottom: 6px;
}

.weui-uploader__hd {
  display: flex;
  padding-bottom: 10px;
  -webkit-box-align: center;
  align-items: center;
}

.weui-uploader__title {
  -webkit-box-flex: 1;
  flex: 1;
}

.weui-uploader__info {
  color: #b2b2b2;
}

.weui-uploader__bd {
  margin-bottom: -4px;
  margin-right: -9px;
  overflow: hidden;
}

.weui-uploader__file {
  float: left;
  margin-right: 9px;
  margin-bottom: 9px;
}

.weui-uploader__img {
  display: block;
  width: 79px;
  height: 79px;
}

.weui-uploader__file_status {
  position: relative;
}

.weui-uploader__file_status:before {
  content: " ";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0,0,0,.5);
}

.weui-uploader__file-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  color: #fff;
}

.weui-uploader__input-box {
  float: left;
  position: relative;
  margin-right: 9px;
  margin-bottom: 9px;
  width: 77px;
  height: 77px;
  border: 1px solid #d9d9d9;
}

.weui-uploader__input-box:after,.weui-uploader__input-box:before {
  content: " ";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  background-color: #d9d9d9;
}

.weui-uploader__input-box:before {
  width: 2px;
  height: 39.5px;
}

.weui-uploader__input-box:after {
  width: 39.5px;
  height: 2px;
}

.weui-uploader__input-box:active {
  border-color: #999;
}

.weui-uploader__input-box:active:after,.weui-uploader__input-box:active:before {
  background-color: #999;
}

.weui-uploader__input {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}

.weui-article {
  padding: 20px 15px;
  font-size: 15px;
}

.weui-article__section {
  margin-bottom: 1.5em;
}

.weui-article__h1 {
  font-size: 18px;
  font-weight: 400;
  margin-bottom: .9em;
}

.weui-article__h2 {
  font-size: 16px;
  font-weight: 400;
  margin-bottom: .34em;
}

.weui-article__h3 {
  font-weight: 400;
  font-size: 15px;
  margin-bottom: .34em;
}

.weui-article__p {
  margin: 0 0 .8em;
}

.weui-msg {
  padding-top: 36px;
  text-align: center;
}

.weui-msg__link {
  display: inline;
  color: #586c94;
}

.weui-msg__icon-area {
  margin-bottom: 30px;
}

.weui-msg__text-area {
  margin-bottom: 25px;
  padding: 0 20px;
}

.weui-msg__title {
  margin-bottom: 5px;
  font-weight: 400;
  font-size: 20px;
}

.weui-msg__desc {
  font-size: 14px;
  color: #999;
}

.weui-msg__opr-area {
  margin-bottom: 25px;
}

.weui-msg__extra-area {
  margin-bottom: 15px;
  font-size: 14px;
  color: #999;
}

@media screen and (min-height:438px) {
  .weui-msg__extra-area {
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
      text-align: center;
  }
}

.weui-flex {
  display: flex;
}

.weui-flex__item {
  -webkit-box-flex: 1;
  flex: 1;
}

.weui-btn {
  margin-top: 15px;
}

.weui-btn:first-child {
  margin-top: 0;
}

.weui-btn-area {
  margin: 1.17647059em 15px .3em;
}

.weui-agree {
  display: block;
  padding: .5em 15px;
  font-size: 13px;
}

.weui-agree__text {
  color: #999;
}

.weui-agree__link {
  display: inline;
  color: #586c94;
}

.weui-agree__checkbox {
  position: absolute;
  left: -9999px;
}

.weui-agree__checkbox-icon {


## 学习路线:

这个方向初期比较容易入门一些,掌握一些基本技术,拿起各种现成的工具就可以开黑了。不过,要想从脚本小子变成黑客大神,这个方向越往后,需要学习和掌握的东西就会越来越多以下是网络渗透需要学习的内容:  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/7a04c5d629f1415a9e35662316578e07.png#pic_center)





**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化资料的朋友,可以点击这里获取](https://bbs.csdn.net/topics/618540462)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值