冲刺(六)

时间:2020-04-28
本文章向大家介绍冲刺(六),主要包括冲刺(六)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

徐利峰

今天完成的:

  实现从服务器上获取数据,并展示到Android端,对每个博文的展示采用的“卡片模型”,添加点击波纹特效,同时对点击后的新闻详情页做了部分,顶部的含历史记录框做了一部分。

明天要做:

  将新闻详情页展示出来,同时尽量加上用户评论信息。将搜索功能进一步完善。

遇到的问题:

  一开始获取服务器端的数据采用的是“volley”,结果数据获取不到,发现他只适合轻量级的传输,于是果断的采用http访问请求,顺利的获取到了数据。

之后对于新闻页中,有部分新闻并没有照片,一开始采用的是默认的照片,之后查阅后发现可以用错误处理图片,以及缓冲加载图片。因此加上之后,看起来美观许多。

同时加入下了刷新。

李浩:

戴伟伟:

摘要:今天写了一些关于通过微信进行第三方登录的东西。。。还有申请微信审核。。。(啥都要审核,我好方),qq开放平台个人资料审核过了,然后还得要过app审核才能拿到appid。。。(淦)

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
    private static final int RETURN_MSG_TYPE_LOGIN = 1;
    private static final int RETURN_MSG_TYPE_SHARE = 2;
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //如果没回调onResp,八成是这句没有写
        MyApp.mWxApi.handleIntent(getIntent(), this);
    }
 
    // 微信发送请求到第三方应用时,会回调到该方法
    @Override
    public void onReq(BaseReq req) {
    }
 
    // 第三方应用发送到微信的请求处理后的响应结果,会回调到该方法
    //app发送消息给微信,处理返回消息的回调
    @Override
    public void onResp(BaseResp resp) {
        LogUtils.sf(resp.errStr);
        LogUtils.sf("错误码 : " + resp.errCode + "");
        switch (resp.errCode) {
 
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                if (RETURN_MSG_TYPE_SHARE == resp.getType()) UIUtils.showToast("分享失败");
                else UIUtils.showToast("登录失败");
                break;
            case BaseResp.ErrCode.ERR_OK:
                switch (resp.getType()) {
                    case RETURN_MSG_TYPE_LOGIN:
                        //拿到了微信返回的code,立马再去请求access_token
                        String code = ((SendAuth.Resp) resp).code;
                        LogUtils.sf("code = " + code);
 
                        //就在这个地方,用网络库什么的或者自己封的网络api,发请求去咯,注意是get请求
                        
                        break;
 
                    case RETURN_MSG_TYPE_SHARE:
                        UIUtils.showToast("微信分享成功");
                        finish();
                        break;
                }
                break;
        }
    }
}

wxActivity

李浩:

大概有两千条数据,由于个别页面布局稍微有变动,所以大概过滤了100条左右的空数据。

Pquery实现新闻数据的爬取:

 1 from pyquery import PyQuery as pq
 2 import pymysql
 3 import random
 4 import time
 5 
 6 model="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
 7 headers={
 8     'Connection': 'keep-alive',
 9     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36 Edg/81.0.416.64',
10     'Content-Type': 'application/x-www-form-urlencoded',
11     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
12     'Accept-Encoding': 'gzip, deflate',
13     'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'
14 }
15 
16 def getId():
17     id=""
18     for i in range(0,10):
19         index=(int)(random.random()*100)%62
20         id+=model[index:index+1]
21     return id+time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
22 
23 def insertData(value):
24     sql="insert into tdnews values(%s,%s,%s,%s,%s,%s,%s,%s)"
25     db=pymysql.connect("localhost", "root", "root", "stdnews", charset='utf8')
26     cursor = db.cursor()
27     try:
28         cursor.execute(sql,value)
29         db.commit()
30         print("插入成功")
31     except:
32         db.rollback()
33         print("插入失败")
34     db.close()
35 
36 
37 def getContent(url):
38     doc = pq(url=url, headers=headers,encoding="utf-8",timeout=None)
39     date=doc('dl.article-info time').text()
40     title=doc('div.page-header h2').text()
41     content_p=doc('div.com-content-article__body p')
42     content_div=doc('div.com-content-article__body div')
43     content=""
44     imgurl=''
45     if(content_div.length>0):
46         for content_item in content_div:
47             if (pq(content_item).find('span').length > 0):
48                 for span in pq(content_item).find('span'):
49                     content += pq(span).text()
50                     if (pq(span).find('img').length > 0):
51                         imgurl += "http://xcbnew.stdu.edu.cn" + str(pq(span).find('img').attr('src')) + ";"
52     else:
53         for content_item in content_p:
54             if(pq(content_item).find('span').length>0):
55                 for span in pq(content_item).find('span'):
56                     content+=pq(span).text()
57                     if(pq(span).find('img').length>0):
58                         imgurl+="http://xcbnew.stdu.edu.cn"+str(pq(span).find('img').attr('src'))+";"
59             else:
60                 content+=pq(content_item).text()
61     print(imgurl)
62     print(title)
63     realdate=date.split("")[1].split("")[0]+"-"+date.split("")[1].split("")[1].split("")[0]+"-"+date.split("")[1].split("")[1].split("")[1].split("")[0]
64     insertData((getId(),title,realdate,content,imgurl,0,0,'newsleader_OoxSmZWy1h20200427195'))
65 
66 for i in range(90,400):
67     url="http://xcbnew.stdu.edu.cn/news"#龙山校区开通“定制公交” 方便师生出行
68     if(i>0):
69         url+="?start="+str(i*10)
70     doc=pq(url=url,headers=headers,encoding="utf-8",timeout=None)
71     hrefs=doc("table.com-content-category__table tbody a")
72     time.sleep(0.1)
73     for href in hrefs:
74         print("http://xcbnew.stdu.edu.cn"+pq(href).attr('href'))
75         getContent("http://xcbnew.stdu.edu.cn"+pq(href).attr('href'))
76         time.sleep(0.1)

数据库截图:

原文地址:https://www.cnblogs.com/xlk3/p/12793832.html