python 报错traceback怎么解决_java调用python提示错误Exception in thread "main" Traceback ,请问如何解决?...

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('div',attrs={"class":"content"}) #搜索div标签并且同时含有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..."

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值