1. jython目前只支持python2,不支持python3.
  2. python中使用第三方包的话需要重新设置lib的地址。
public void getHtmlByTxt(String path) {
// TODO 编写调用python抓取页面的程序
PySystemState sys = Py.getSystemState();
sys.path.add("D:\\Python\\Python36\\Lib\\site-packages\\");
PythonInterpreter interpreter = new PythonInterpreter();
String pyPath = this.getClass().getResource("/py/game.py").getPath().substring(1);
//String pyPath = this.getClass().getClassLoader().getResource("py/game.py").getPath();
logger.info(pyPath);
interpreter.exec("import sys");
interpreter.execfile(pyPath);
}
# coding=utf-8
import io
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities if __name__ == '__main__':
url = "http://data.champdas.com/match/data-10258.html"
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 ") obj = webdriver.PhantomJS(executable_path=r'D:\phantomjs\bin\phantomjs.exe',desired_capabilities=dcap)
obj.get(url)
html = obj.page_source
obj.quit() fw = open("D:\\test.html","w", encoding='utf-8')
fw.write(html)
fw.close()

jython研究笔记的更多相关文章

  1. jython安装与配置

    安装jython 0. 计算机中要安装jdk 1. 在官网www.jython.org上找到下载页面,然后下载jython-installe 2. 在cmd.exe中运行java -jar jytho ...

  2. jython安装

    下载了jython后:http://www.cr173.com/soft/9719.html 这是我当时下载的网站 官网很慢开始->运行->cmd->打开dos命令窗口,转到jyth ...

  3. jython 2.7 b3发布

    Jython 2.7b3 Bugs Fixed - [ 2108 ] Cannot set attribute to instances of AST/PythonTree (blocks pyfla ...

  4. 基于jython操作hbase

    一.前言 关于jython介绍,直接上官网www.jython.org,可以得到详细资料,这里只介绍一下jython操作hbase的一些方法,本质上和用java操作hbase差不多,只不过语法换成了p ...

  5. Jython概要

    1.安装jython 1.1 进入http://www.jython.org/downloads.html ,网页上会显示当前最稳定的版本(The most current stable releas ...

  6. jython学习笔记3

    1.os.environ["HOME"] 为什么这句话在我的STS中打印不出东西,还报错 Method Description close() Close file fileno( ...

  7. jython语言学习笔记

    1.变量可以随便定义,不限制类型,不限制数值.开头空4个空格,使用def定义函数,可以嵌套,可以传参. 2.每个语句结束的时候没有分号.定义类的时候没有括号.在print语句的后面有格式转换时要加上% ...

  8. Jython安装步骤

    1.下载安装包 2.执行安装 Java -jar [此处是下载的jython jar包名],或者双击jar包夜可以 3.配置环境变量 新增JYTHON_THOME的环境变量,并设置为安装路径. 配置c ...

  9. JDK和Jython安装

    下载JAVA SE,下载地址请到oracle官方网站下载. JDK下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8- ...

随机推荐

  1. c#pdf查看器

    Free Spire.PDF for .NET is a Community Edition of the Spire.PDF for .NET, which is a totally free PD ...

  2. Python学习札记(三十八) 面向对象编程 Object Oriented Program 9

    参考:多重继承 NOTE #!/usr/bin/env python3 class Animal(object): def __init__(self, name): self.name = name ...

  3. ongene database

    http://ongene.bioinfo-minzhao.org/index.html

  4. json.dump()和json.load()

    import json,time # save data to json file def store(data): with open('data.json', 'w') as fw: # 将字典转 ...

  5. 获取文本中所有的<img>标签的位置,获取所有img标签的src

    public static int[] GetImagePos(string str) { str = str.Replace("$", " "); str = ...

  6. 移动web开发适配方案之Rem

    移动端为什么要做适配 移动端相对PC端来说大部分浏览器内核都是基于Webkit的,所以大部分都支持CSS3的最新语法.但是由于手机的屏幕尺寸和分辨率都不太一样(尤其是安卓),所以不得不对不同分辨率的手 ...

  7. C# 对json对象嵌套数组

    看图: 这里可以看到是二层嵌套!!使用C#如何实现?? 思路:使用list集合实现 → 建立类 → list集合 → 微软的   Newtonsoft.Json  (一款.NET中开源的Json序列化 ...

  8. 微信授权登录,关于调不起授权页面,无法响应回调方法,获取不到code 详解

    前期准备工作:申请AppId,下载资源包jar.文档等. 微信授权登录步骤: 1. 第三方发起微信授权登录请求,微信用户允许授权第三方应用后,微信会拉起应用或重定向到第三方网站,并且带上授权临时票据c ...

  9. navicat链接mysql 8 出现 2015 authentication plugin 'caching_sha2_password' 错误

    使用mysql自带的 MySQL 8.0 Command Line Client - Unicode 登录, 然后使用命令: alter user 'root'@'localhost' identif ...

  10. python将字符转换为字典

    参考文章Python 如何将字符串转为字典 注意: 使用json的时候一定要注意是loads而不是load 即:user_dict = json.loads(user_info) 注意: 用eval( ...