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('<span>(.*?)</span>',re.S)
lists = re.findall(pattern,str(item))
for list in lists:
print 'NO',number,':',list.decode('utf-8'),'\n'
print "End..."
运行时,控制台出现如下错误,请问如何修改?
闭关修行中......