首页
畅所欲言
友情链接
壁纸大全
数据统计
推荐
工具箱
在线白板
Search
1
职教云小助手重构更新,职教云助手最新版下载地址【已和谐】
14,536 阅读
2
职教云-智慧职教,网课观看分析(秒刷网课)
11,825 阅读
3
gradle-5.4.1-all.zip下载
9,810 阅读
4
职教云-智慧职教,签到补签分析(逆天改命系列)
8,300 阅读
5
一个优秀的程序员从写文档开始:免费领14个月语雀云笔记会员
7,116 阅读
学习笔记
Web
Python
转载文章
算法刷题
JS逆向
综合笔记
安卓
物联网
Java
C
资源收集
软件收藏
网络资源
影视专辑
TED英语角
随便写写
随手拍
登录
/
注册
Search
Lan
累计撰写
622
篇文章
累计收到
632
条评论
首页
栏目
学习笔记
Web
Python
转载文章
算法刷题
JS逆向
综合笔记
安卓
物联网
Java
C
资源收集
软件收藏
网络资源
影视专辑
TED英语角
随便写写
随手拍
页面
畅所欲言
友情链接
壁纸大全
数据统计
推荐
工具箱
在线白板
搜索到
622
篇与
的结果
2020-10-08
【开源程序】API管理程序
后端用的Django,前面页面用的是韩小韩api扒下来的页面(请勿见怪)Github地址:暂无
2020年10月08日
860 阅读
0 评论
2 点赞
2020-10-04
汤圆创作小说检索信息采集
前段时间,因为一些原因,所以需要对这个汤圆创作的小说进行检索,于是写了几行python代码解析了一下搜索出来的结果的信息。# -*- coding: utf-8 -*- """ ------------------------------------------------- @ Author :Lan @ Blog :www.lanol.cn @ Date : 2020/9/30 @ Description:I'm in charge of my Code ------------------------------------------------- """ import requests import parsel for i in range(1, 10094): url = f'https://www.itangyuan.com/search/book/%E4%B8%80%20%E7%94%9F.html?page={i}' res = requests.get(url).text xpathFile = parsel.Selector(res) author = xpathFile.xpath("//p[@class='author']/a/text()").extract() name = xpathFile.xpath("//p[@class='bname']/a/text()").extract() info = xpathFile.xpath("//p[@class='rw_info']/text()").extract() for index, value in enumerate(name): if '一' in value.replace(' ', '') and '生' in value.replace(' ', ''): if int(info[index].split('阅读')[0].replace(' ', '')) < 1000: print(value, author[index], info[index].split('/')[-1]) print(f'已检测至第{i}页')大概就是搜索出所有小说名包含一和生字且阅读量小于1000的。
2020年10月04日
970 阅读
0 评论
0 点赞
2020-09-29
Django设置全局模板变量
最近由于需要,之前做的一个项目需要将图片文件转移至COS对象储存,因为服务器网络不行,图片加载太慢。经过一番猛如虎的操作,目的还是达到了。但是问题来了,图片上传好了,那怎么访问呢,我一开始想的是在数据里加一个表,就是用来存一些默认的字段。但是每次都得去取一次,然后还得返回,感觉实在有点浪费,于是想着有没有全局模板变量,就像我在模板中可以直接调用request.user一样。经过百度,找到了答案。先在一个view中添加你要返回的默认值然后在settings中的Templates->OPTIONS->context_processors进行注册(大概是这样叫吧,个人理解)然后就可以直接在模板中引用这个值了。
2020年09月29日
724 阅读
0 评论
0 点赞
2020-09-26
安卓在子线程传值给主线程,通过Handler传值
昨晚上在进行http请求获取数据并修改listview的时候遇到了一个问题Only the original thread that created a view hierarchy can touch its views大概意思就是:只有创建了视图层级的原始线程才可以修改这个视图于是我百度了一下,然后大概解决方案是这样子的,子线程通过handler传值给主线程,主线程接收后,再进行修改listview。Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 1) { Bundle data = msg.getData(); String val = data.getString("value"); //设置UI tvCode.setText(val); Log.i(TAG, "请求结果:" + val); } else if (msg.what ==0) { Toast.makeText(getApplicationContext(),"请求资源不成功",Toast.LENGTH_LONG).show(); } } }; /** * 处理网络请求的线程 */ private class RequestThread extends Thread { @Override public void run() { //网络请求 String string = 请求结果 Message msg = new Message(); Bundle data = new Bundle(); //将获取到的String装载到msg中 data.putString("value", string); msg.setData(data); msg.what = 1; //发消息到主线程 handler.sendMessage(msg); } } //点击事件启动新线程 public void test(View v){ new RequestThread().start(); }解决方法原链接:https://blog.csdn.net/LJX_ahut/article/details/89432576经过实践着实有用。获取前:获取后:MainActivity.java代码package ink.cik.logininfoapp; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.net.wifi.aware.DiscoverySession; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Adapter; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.Toast; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.util.ArrayList; import java.util.List; import ink.cik.logininfoapp.eneity.userInfo; import ink.cik.logininfoapp.help.httpHelper; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class MainActivity extends AppCompatActivity { private final Gson gson = new Gson(); @SuppressLint("HandlerLeak") Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 1) { Bundle data = msg.getData(); String val = data.getString("value"); List<userInfo> userInfoList = parseJson(val); ListView listView = (ListView) findViewById(R.id.listInfo); ArrayList<String> list = new ArrayList<String>();//数据源集合创建 for (userInfo userInfo : userInfoList) { list.add(userInfo.getUserName()); } ArrayAdapter<String> adapter = new ArrayAdapter<String>( MainActivity.this, android.R.layout.simple_list_item_1, list ); listView.setAdapter(adapter); } else if (msg.what == 0) { Toast.makeText(MainActivity.this, "数据获取失败,请检查网络!", Toast.LENGTH_SHORT); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.searchButton); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAll(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu, menu); return true; } private void getAll() { final httpHelper httpHelper = new httpHelper(); new Thread(new Runnable() { @Override public void run() { try { String res = httpHelper.httpGet("https://api.565.ink/login/getAll?passwd=lanol666"); Log.d("结果:", res); Message msg = new Message(); Bundle data = new Bundle(); //将获取到的String装载到msg中 data.putString("value", res); msg.setData(data); msg.what = 1; handler.sendMessage(msg); } catch (Exception e) { e.printStackTrace(); } } }).start(); } private List<userInfo> parseJson(String JsonData) { Gson gson = new Gson(); List<userInfo> userInfoList = gson.fromJson(JsonData, new TypeToken<List<userInfo>>() { }.getType()); return userInfoList; } }
2020年09月26日
1,042 阅读
0 评论
0 点赞
2020-09-24
Android在子线程显示Toast闪退,Can"t toast on a thread that has not called Loop
新建一个类toastHelppackage ink.cik.logininfoapp.eneity; import android.content.Context; import android.os.Looper; import android.widget.Toast; public class toastHelp { static Toast toast = null; public static void show(Context context, String text) { try { if (toast != null) { toast.setText(text); } else { toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); } toast.show(); } catch (Exception e) { //解决在子线程中调用Toast的异常情况处理 Looper.prepare(); Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); Looper.loop(); } } }然后需要用的时候直接调用toastHelp.show(LoginActivity.this, responseInfo.getInfo());
2020年09月24日
1,095 阅读
0 评论
0 点赞
2020-09-24
利用okhttp3调用接口,用gson解析json数据
开心,总算搞好了调用接口获取所有用户信息,然后打印出来了。MainActivity.javapackage ink.cik.logininfoapp; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.IOException; import java.util.List; import java.util.Map; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class MainActivity extends AppCompatActivity { private final Gson gson = new Gson(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.loginButton); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText userName = findViewById(R.id.userName); EditText passWord = findViewById(R.id.passWord); Toast.makeText(MainActivity.this, userName.toString(), Toast.LENGTH_SHORT).show(); verLogin(); } }); } private void verLogin() { new Thread(new Runnable() { @Override public void run() { try { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url("https://api.565.ink/login/getAll?passwd=lanol666").build(); Response response = client.newCall(request).execute(); String responsedata = response.body().string(); Log.d("返回数据:", responsedata); parseJson(responsedata); } catch (IOException e) { e.printStackTrace(); } } }).start(); } private void parseJson(String JsonData) { Gson gson = new Gson(); List<userInfo> userInfoList = gson.fromJson(JsonData, new TypeToken<List<userInfo>>() { }.getType()); for (userInfo userInfo : userInfoList) { Log.d("信息:", userInfo.getUserName()); } } }userInfo.javapackage ink.cik.logininfoapp; public class userInfo { private int id; private String userName; private String passWord; private String nation; private int age; private String tel; public int getAge() { return age; } public String getNation() { return nation; } public int getId() { return id; } public String getPassWord() { return passWord; } public String getTel() { return tel; } public String getUserName() { return userName; } public void setAge(int age) { this.age = age; } public void setId(int id) { this.id = id; } public void setNation(String nation) { this.nation = nation; } public void setPassWord(String passWord) { this.passWord = passWord; } public void setTel(String tel) { this.tel = tel; } public void setUserName(String userName) { this.userName = userName; } }
2020年09月24日
1,162 阅读
0 评论
0 点赞
2020-09-23
Android OKHttp发送get网络请求实例
今天总算把安卓的网络请求弄了一下了。获取的是我自己做的接口:https://api.565.ink/one/随机一句英语,不得不说换一门语言,写法上真的有点不适应。MainActivify.javapackage ink.cik.firsthttpapp; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import java.io.IOException; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class MainActivity extends AppCompatActivity { TextView responseText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.btnSyncTest); responseText = findViewById(R.id.response_text); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d("点击事件", "点击发送请求按钮"); sendRequest(); } }); } private void sendRequest() { //开启线程发送请求 new Thread(new Runnable() { @Override public void run() { try { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url("https://api.565.ink/one/").build(); Response response = client.newCall(request).execute(); String responseData = response.body().string(); showResponse(responseData); } catch (IOException e) { e.printStackTrace(); } } }).start(); } private void showResponse(final String response) { runOnUiThread(new Runnable() { @Override public void run() { responseText.setText(response); } }); } }AndroidMainifest.xml<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ink.cik.firsthttpapp"> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>activity_main.xml<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btnSyncTest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="同步测试" /> <Button android:id="@+id/btnAsyncTest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="异步测试" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="6" android:hint="输入用户编号" android:inputType="number" /> <Button android:id="@+id/btnParamTest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="doParamTest" android:text="传参测试" /> </LinearLayout> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/response_text" android:layout_width="match_parent" android:layout_height="match_parent" /> </ScrollView> </LinearLayout>build.gradleapply plugin: 'com.android.application' android { compileSdkVersion 30 buildToolsVersion "30.0.2" defaultConfig { applicationId "ink.cik.firsthttpapp" minSdkVersion 30 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation 'com.squareup.okhttp3:okhttp:4.9.0' implementation 'com.squareup.okio:okio:2.8.0' }总结一下踩得一些坑。坑一:导入okhttp包导错了地方。书上说,要在build.gradle中导入okhttp和okio于是乎。。这两个里面果断的选择了第一个,因为名字是自己取的,按照python来说,默认的都是系统的。结果出错了,其实是Module:app这个坑二:本来我是本地搭建的环境,然后电脑端自己修改的hosts,将lan指向了127.0.0.1于是乎。坑三:原本用的http,结果不行,百度发现得https
2020年09月23日
1,304 阅读
2 评论
1 点赞
1
...
42
43
44
...
89