java调用python提示错误Exception in thread "main" Traceback ,请问如何解决?

 蜜小嘟_546 发布于 2022-10-25 17:50

Eclipse中java代码调用python脚本时提示错误Exception in thread "main" Traceback (most recent call last):,请问如何解决?
Eclipse中配置了python2.7和jython2.7。
java代码如下:

package test;

import org.python.util.PythonInterpreter;

public class ThirdJavaScript {
    public static void main(String args[]) {
        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile("E:\\python\\python_demo\\see_xiaohua.py");
    }
}

python脚本代码如下:

# coding:utf-8
#!/usr/bin/python
import urllib2#与下面脚本对比没有被注释
import re#与下面脚本对比没有被注释
from bs4 import BeautifulSoup#与下面脚本对比没有被注释
number =0  #定义序号变量
page = raw_input("Please input page:")
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
request = urllib2.Request('http://www.qiushibaike.com/hot/page/'+str(page)+'/?s=4915651',headers = headers)
response = urllib2.urlopen(request)
html = response.read()   #获取页面源码
soup = BeautifulSoup(html,"html.parser")
items = soup.find_all('p',attrs={"class":"content"}) #搜索p标签并且同时含有class=content内容

for item in items:
    number +=1
    pattern = re.compile('(.*?)',re.S)
    lists = re.findall(pattern,str(item))
    for list in lists:
        print 'NO',number,':',list.decode('utf-8'),'\n'
    
print "End..."

运行时,控制台出现如下错误,请问如何修改?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有