pycharm 安装依赖包过慢解决方法

简单,在 terminal 中输入如下命令即可,例如安装 requests:pip3 install requests -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 其他国内源参看:https://cway.top/post/831.html

java selenium webdriver 无头模式参数设置

java webdriver 无头模式参数设置 Chrome 设置 mac linux 需浏览器 59 版本以上,windows 60 版本以上 ChromeOptions options = new ChromeOptions();// 设置 chrome 的无头模式 options.addArguments("--headless"); options.addArguments("--no-sandbox"); options.addArguments("--disable-gpu"); options.addArguments("--disable-dev-shm-usage"); WebDriver driver = new ChromeDriver(options);selenium add_argument 参数表 https://peter.sh/experiments/chromium-command-line-switches/chrome_options.add_argument('--user-agent=""') # 设置请求头的 User-Agentchrome_options.add_argument('--window-size=1280x1024') # 设置浏览器分辨率(窗口大小)chrome_options.add_argument('--start-maximized') # 最大化运行(全屏窗口), 不设置,取元素会报错chrome_options.add_argument('--disable-infobars') # 禁用浏览器正在被自动化程序控制的提示chrome_options.add_argument('--incognito') # 隐身模式(无痕模式)chrome_options.add_argument('--hide-scrollbars') # 隐藏滚动条, 应对一些特殊页面chrome_options.add_argument('--disable-javascript') # 禁用 javascriptchrome_options.add_argument('--blink-settings=imagesEnabled=false') # 不加载图片, 提升速度chrome_options.add_argument('--headless') # 浏览器不提供可视化页面chrome_options.add_argument('--ignore-certificate-errors') # 禁用扩展插件并实现窗口最大化chrome_options.add_argument('--disable-gpu') # 禁用 GPU 加速chrome_options.add_argument('–disable-software-rasterizer')chrome_options.add_argument('--disable-extensions')chrome_options.add_argument('--start-maximized') 参考:https://blog.csdn.net/weixin_43968923/article/details/87899762 火狐设置 FirefoxOptions options1 = new FirefoxOptions(); options1.addArguments("-headless");

Java selenium+webdriver 使用教程

java selenium+webdriver 使用教程webdriver 驱动下载Chrome:http://npm.taobao.org/mirrors/chromedriver/https://chromedriver.storage.googleapis.com/index.htmlFirefox:https://github.com/mozilla/geckodriver/releases所需依赖 只需要 selenium-server 依赖即可 <dependencies><!-- <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-api</artifactId> <version>3.141.59</version> </dependency>--> <!-- 或者用注释的坐标亦可 --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>3.141.59</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.1</version> </dependency> </dependencies>示例代码 以下是模拟打开本站登陆页面,各位可使用 Katalon Recorder 浏览器插件 自动生成代码,也可以参考下之前的 一个示例 public static void main(String[] args) throws InterruptedException {System.setProperty("webdriver.chrome.driver", "C:\\Users\\Administrator\\Downloads\\chromedriver_win32\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().deleteAllCookies(); // 与浏览器同步非常重要,必须等待浏览器加载完毕 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("https://cway.top"); Thread.sleep(2000); driver.findElement(By.linkText(" 登录后台 ")).click(); Thread.sleep(2000); driver.close(); driver.quit();}其他操作 打开各种浏览器//IE 浏览器System.setProperty("webdriver.ie.driver", ".\\Tools\\IEDriverServer.exe");WebDriver driver = new InternetExplorerDriver();//ChromeSystem.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe");WebDriver driver = new ChromeDriver();//FireFox(自定义安装)System.setProperty("webdriver.firefox.bin", "D:\\ProgramFiles\\Mozilla Firefox\\firefox.exe");//FireFox 版本大于 48, 默认安装System.setProperty("webdriver.firefox.marionette", ".\\Tools\\geckodriver.exe");//FireFox 版本小于 48System.setProperty("webdriver.firefox.marionette", ".\\Tools\\geckodriver.exe");WebDriver driver = new FirefoxDriver();亦可用 ChromeDriverService 类构建驱动String webDriverPath = LagouSpider.class.getResource("chromedriver.exe").getPath(); // 这里需要注意一定要和打开的 Chrome 版本匹配 System.setProperty("webdriver.chrome.driver", webDriverPath); // 构建驱动 ChromeDriverService service = new ChromeDriverService.Builder(). usingDriverExecutable(new File(webDriverPath)).usingAnyFreePort().build(); try {service.start(); } catch (IOException e) {e.printStackTrace(); } // 获取 Web 驱动 WebDriver driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());只是最后要关闭 service // 退出驱动线程 driver.quit(); // 关闭 service 服务 service.stop();打开 URL// 后退, 跳转到上一页driver.navigate().back();// 前进, 跳转到下一页driver.navigate().forward ();// 当前页刷新driver.navigate().refresh();// 浏览器窗口最大driver.manage().window().maximize();// 自定义设置浏览器尺寸driver.manage().window().setSize(new Dimension(width, heigth));关闭浏览器// 关闭当前页面driver.close(); // 关闭由 selenium 所启动的所有页面driver.quit();返回当前页标题与 URL // 返回当前页面的 Ttile String title = driver.getTitle(); // 返回当前页面的 url String currentUrl = driver.getCurrentUrl();其它常见方法// 返回当前的浏览器的窗口句柄 String currentWindowHandle = driver.getWindowHandle() // 返回当前的浏览器的所有窗口句柄 Set<String> allWindowHandles = driver.getWindowHandles(); // 返回当前页面的源码 String currentPageSource = getPageSource() // 通过 xpath 获取元素 使用 By 还可以通过其他条件获取 WebElement titleElement = driver.findElement(By.xpath(titleExpression)); // 获取文本 String titleElementText = titleElement.getText(); // 获取属性 String titleElementHref = titleElement.getAttribute("href");参考:https://www.cnblogs.com/andrew209/archive/2004/01/13/9011399.html

关闭 HtmlUnit 日志信息 屏蔽报错信息

对于 htmlunit 控制台报错信息不能关闭的情况,将下列代码加入报错代码前即可,例如可加在代码最前面LogManager.getLogManager().reset();其它方法可参考:https://blog.csdn.net/gyxscnbs/article/details/51357407对于纯 java 项目 (未引入其它日志系统) 的警告信息,可在 classpath 中加入 logging.properties 文件解决,文件内容:java.util.logging.ConsoleHandler.level = FINEjava.util.logging.ConsoleHandler.encoding = UTF-8

Maven 固定 jdk 版本 将依赖包都打进 jar 包教程

很简单,pom 中加入这两个插件即可,第一个插件指定要编译的 jdk 版本、编码等信息,第二个插件 mainClass 中填入 jar 启动类的全限定类名。 <build> <plugins> <!-- 强制 maven 以 jdk8 编译 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打包时包将所有依赖打进去 --> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> 对于第一个插件,其它设置有 <plugin> <!-- 指定 maven 编译的 jdk 版本, 如果不指定,maven3 默认用 jdk 1.5 maven2 默认用 jdk1.3 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <!-- 一般而言,target 与 source 是保持一致的,但是,有时候为了让程序能在其他版本的 jdk 中运行 (对于低版本目标 jdk,源代码中不能使用低版本 jdk 中不支持的语法),会存在 target 不同于 source 的情况 --> <source>1.8</source> <!-- 源代码使用的 JDK 版本 --> <target>1.8</target> <!-- 需要生成的目标 class 文件的编译版本 --> <encoding>UTF-8</encoding><!-- 字符集编码 --> <skipTests>true</skipTests><!-- 跳过测试 --> <verbose>true</verbose> <showWarnings>true</showWarnings> <fork>true</fork><!-- 要使 compilerVersion 标签生效,还需要将 fork 设为 true,用于明确表示编译版本配置的可用 --> <executable><!-- path-to-javac --></executable><!-- 使用指定的 javac 命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> --> <compilerVersion>1.3</compilerVersion><!-- 指定插件将使用的编译器的版本 --> <meminitial>128m</meminitial><!-- 编译器使用的初始内存 --> <maxmem>512m</maxmem><!-- 编译器使用的最大内存 --> <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar </compilerArgument><!-- 这个选项用来传递编译器自身不包含但是却支持的参数选项 --> </configuration></plugin> 第二个插件执行打包,点击 idea 右侧 Maven -> 项目名 -> Plugins-> assembly -> assembly:assembly 执行即可,如图:

Maven 固定 jdk 版本 将依赖包都打进 jar 包教程

Java 获取 js 渲染后的 html 页面源码实战 (获取金价)

以下代码获取京东积存金实时价格,并高于预期卖出价或低于预期买入价时弹窗或微信提醒。依赖 依赖 htmlunit、jsoup 两个包,htmlunit 用于获取页面,jsoup 用于解析 html 获取指定值。<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>goldNotice</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <maven.compiler.resource>1.8</maven.compiler.resource> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>htmlunit</artifactId> <version>2.45.0</version> </dependency> <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.12.1</version> </dependency> </dependencies> <build> <plugins> <!-- 强制 maven 以 jdk8 编译 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打包时包将所有依赖打进去 --> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build></project>代码import com.gargoylesoftware.htmlunit.BrowserVersion;import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;import com.gargoylesoftware.htmlunit.WebClient;import com.gargoylesoftware.htmlunit.html.HtmlPage;import org.jsoup.Jsoup;import org.jsoup.nodes.Document;import org.jsoup.select.Elements;import javax.swing.*;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.net.URLConnection;import java.util.Date;import java.util.logging.LogManager;public class Main {public static void main(String[] args) {LogManager.getLogManager().reset();// 预期卖出价 float expectPrice = 399;// 预期买入价 float lowPrice = 390;// 间隔时间 默认 2s long sec = 2000;// 请求等待时间 long reqSec = 5000; for (int i = 0; i <= 3; i++) {if (args.length > 0 && i == 0) expectPrice = Float.parseFloat(args[0]); if (args.length > 1 && i == 1) lowPrice = Float.parseFloat(args[1]); if (args.length > 2 && i == 2) sec = Long.parseLong(args[2]); if (args.length > 3 && i == 3) reqSec = Long.parseLong(args[3]); } System.out.println(" 数据加载中请稍候……"); WebClient webClient = new WebClient(BrowserVersion.CHROME);// 模拟 CHROME 浏览器 try {webClient.setJavaScriptTimeout(5000); webClient.getOptions().setUseInsecureSSL(true);// 接受任何主机连接 无论是否有有效证书 webClient.getOptions().setJavaScriptEnabled(true);// 设置支持 javascript 脚本 webClient.getOptions().setCssEnabled(false);// 禁用 css 支持 webClient.getOptions().setThrowExceptionOnScriptError(false);//js 运行错误时不抛出异常 webClient.getOptions().setTimeout(100000);// 设置连接超时时间 webClient.getOptions().setDoNotTrackEnabled(false); HtmlPage page = webClient.getPage("https://m.jdjygold.com/finance-gold/newgold/index/?ordersource=2&jrcontainer=h5&jrlogin=true&utm_source=Android_url_1609033920704&utm_medium=jrappshare&utm_term=wxfriends");// 加载 js 需要时间故延迟默认 5s Thread.sleep(reqSec); while (true) {// 使用 Jsoup 解析 html Document document = Jsoup.parse(page.asXml()); Elements span01 = document.getElementsByClass("price_span01"); String price = span01.text(); String localeString = new Date().toLocaleString(); System.out.println(localeString + " " + price); String msg = localeString + " 价格已达到预定值:" + price; String lowMsg = localeString + " 价格已低于预定值:" + price; float goldPrice = Float.parseFloat(price); if (msg != null && goldPrice >= expectPrice) {JOptionPane.showConfirmDialog(null, msg, " 达到预期卖出价提示 ", JOptionPane.CLOSED_OPTION);// 若部署在服务器上则使用 Server 酱提醒// getUrl("https://sc.ftqq.com/xxxxxxxxxxxxxx.send?text="+msg); return; } if (msg != null && goldPrice <= lowPrice) {JOptionPane.showConfirmDialog(null, lowMsg, " 低于预期买入价提示 ", JOptionPane.CLOSED_OPTION);// getUrl("https://sc.ftqq.com/xxxxxxxxxxxxxx.send?text="+lowMsg); return; } Thread.sleep(sec); } } catch (FailingHttpStatusCodeException e) { // TODO 自动生成的 catch 块 e.printStackTrace();} catch (MalformedURLException e) { // TODO 自动生成的 catch 块 e.printStackTrace();} catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace();} catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace();} finally {webClient.close(); } } public static void getUrl(String toUrl) throws IOException {URL url = new URL(toUrl); // 建立连接 URLConnection urlConnection = url.openConnection(); // 连接对象类型转换 HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; // 设定请求方法 httpURLConnection.setRequestMethod("GET"); // 获取字节输入流信息 InputStream inputStream = httpURLConnection.getInputStream(); // 字节流转换成字符流 InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8"); // 把字符流写入到字符流缓存中 BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line = null; // 读取缓存中的数据 while ((line = bufferedReader.readLine()) != null) {System.out.println(line); } // 关闭流 inputStream.close();}}使用方法 打包后直接执行命令java -jar xxx.jar 390 360第一个数字为预期卖出价;第二个为预期买入价,即当价格高于 390 或低于 360 提醒并关闭程序。第三个参数设置间隔时间,单位毫秒;第四个参数设置请求等待时间,即启动时加载数据的等待时间,有时候网络不好时间短可能加载不出来,代码不填时默认 5s,一般足矣无需带第四个参数。例如:java -jar goldNotice-1.0-SNAPSHOT-jar-with-dependencies.jar 400 391.6 2500 3000在服务器上部署请配置 Server 酱 key 并将弹窗代码注释。更多拓展可自行修改代码。

Firefox 火狐手机版安装插件及 PC 端书签整理插件

Firefox 火狐国际版 (安卓) 安装插件Firefox Nightly(ARM64 版) https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/mobile.v2.fenix.nightly.latest.arm64-v8a/artifacts/public/build/arm64-v8a/target.apk其它版本见官方库:https://firefox-ci-tc.services.mozilla.com/tasks/index/mobile.v2.fenix下载 Nightly 版,设置里找到关于,多次点击 Nightly 图标,回到设置界面,然后点击「自定义附加组件收藏集」,输入收藏集所有者:15434003,收藏集名称:1(值任意,中文可能会添加失败),重启浏览器即可。你也可以添加自己的应用集然后使用自己的应用集 ID。参考酷安@hana_shirosakiFirefox 书签整理插件(适合 PC 端)Bookmark Dupes:检测重复书签、空文件夹并删除Bookmarks clean up:检测重复书签、空文件夹并删除、合并同名文件夹,并且提供检测失效链接,功能与上一个插件互补Bookmarks Organizer:检测 404、403 等无效链接,一键删除或手动处理,也能检测重复链接、无标题链接Auto-Sort Bookmarks:让书签根据标题字母、URL、创建时间、访问次数等条件排序,让书签更加井井有条floccus:书签同步工具,支持 webdav

IntelliJ IDEA 常用统一设置(Linux/Mac/Windows)

说明:除了以下说明的配置地方外,其它尽量保持默认,这样有利于团队代码风格的统一。 运行 VM 配置:推荐高内存机器配置,8G 内存保持默认即可。参考:https://github.com/judasn/IntelliJ-IDEA-Tutorial/blob/master/installation-directory-introduce.md 一、文件编码 IDE 的编码默认修改为 UTF-8,Project Encoding 修改为 UTF-8;注意:Linux 默认编码为 UTF-8,而 Windows 默认是 GBK,所以从 Windows 新建的文件转到 Linux 会变成乱码,而通过这样的修改之后,就能保持多平台统一的编码,Mac 下默认也是 UTF-8。 二、换行符 换行符统一修改为 Linux 和 Mac 下用的 \n 三、Tab 键使用 4 个空格缩进 注意:是不选择! 四、代码提示不区分大小写 五、设置自动 import 包(可选,对于不能 import * 的要求的,建议不要用这个) 如果非要用这个自动导入却不想导入 * 的,可以通过配置这个来解决 调整 import 包导入的顺序,保持和 Eclipse 一致: 空行import java.*空行import javax.*空行import com.*空行import all other imports空行import static all other imports 六、右下角显示内存 点击右下角可以回收内存。 七、显示行数和方法线 八、新建类时加入标准的 Javadoc 注释(即:@author、@date) 说明:@date 可能不是标准的 Javadoc,但是在业界标准来说,这个已经成为 Javadoc 必备的注释,因为大多数人都用这个来标注日期。 建议:注释不要太个性,比如自定义类说明,日期时间字段等等;尽量保持统一的代码风格,建议参考阿里巴巴 Java 开发手册。 四个文件都加上这个说明:/** * This is Description * * @author ${USER} * @date ${YEAR}/${MONTH}/${DAY} */ 注意:Javadoc 的关键字与说明要隔开一行。日期格式:年 / 月 / 日(参考阿里巴巴 Java 开发手册),作者可以用系统默认也可以写死。 九、Google 代码风格(可选) 注意:Google 代码风格为 2 个空格缩进,根据需要修改为 4 个空格缩进。 官网:https://github.com/google/styleguide 下载: 修改为 4 个空格: 上面只是针对 Java 文件的设置,比如 CSS 这些都是需要手动修改的。 参考:https://github.com/judasn/IntelliJ-IDEA-Tutorial/blob/master/theme-settings.mdhttps://www.cnblogs.com/wangmingshun/p/6427088.html

IntelliJ IDEA 常用统一设置(Linux/Mac/Windows)

谷歌 Chrome 浏览器小恐龙游戏刷分

当电脑断网用谷歌浏览器浏览网页时会出现一只萌萌哒小恐龙,按空格键即可开始游戏,是继蜘蛛纸牌之后又一上班划水神奇,但是看似简单的游戏跑高分倒是有点困难,下面分享下可以跑高分的方法(或称为作弊码也行)以下需在 F12->console 中输入: 满分 Runner.instance_.setSpeed(99999); 无敌 Runner.instance_.gameOver = function(){}

基于 SpringBoot+VUE 的开源 blog (helloblog)

基于 SpringBoot 实现零配置让系统的配置更简单,使用了 Mybatis-Plus 快速开发框架,在不是复杂的查询操作下,无需写 sql 就可以快速完成接口编写。 后台管理系统使用了 vue 中流行的 ant,另外前后交互使用了 JWT 作为令牌,进行权限、登录校验。 项目下载地址 后端 API https://github.com/byteblogs168/hello-blog 后端管理系统 https://github.com/byteblogs168/hello-blog-admin 前端主题地址: https://github.com/byteblogs168/theme-default3/helloblog 博客功能 1、接入 GitHub 登录,游客可使用 GitHub 登录后进行评论等 2、文章管理:新增、编辑、删除,支持 MD 语法 3、文章可设置是否允许评论、设置标签、分类、支持博客搬家、自定义排序 4、仪表盘:服务器状态、博客浏览量、最热文章一览无余 5、分类管理:分类列表、分类增删查改 6、标签管理:标签列表、标签增删查改 7、友链管理:友链排序、友链简介 8、用户管理:锁定用户、删除用户 9、日志管理:对指定的接口进行监控 10、菜单管理:自定义首页菜单项 11、社交管理:自定义个人社交项 12、系统配置 - 站点信息:自定义网站信息、版权信息、关键词等 13、系统配置 - 歌单配置:配置网易云歌单信息 (站点播放器)14、系统配置 - 存储配置:接入阿里云 OSS、七牛云、腾讯云 COS、服务器 OSS15、个人设置 - 定义个人信息、个性签名等信息 16、文章归档:按照月份查询博客文章并进行分类