Javacode transfers python prompt "Exception in thread "main" Traceback (most recent call last):"

Hi all!
I use eclipse,I have a java project,when my java program transfers python script,the console prompt “Exception in thread “main” Traceback (most recent call last):”.
My java code:

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");
    }
}

My python code:

# 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"}) 

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..."

the error picture is:


How to modify?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.