The code worked in IDLE, but not in Pycharm, this is the complete code:
import sys
import urllib
import urllib2
from bs4 import BeautifulSoup
type_keyword = "唯品会与消协共同搭建绿色维权通道"
url = "http://www.baidu.com/s?wd=" + urllib.quote(type_keyword.decode(sys.stdin.encoding).encode('gbk'))
openpage = urllib2.urlopen(url).read()
soup = BeautifulSoup(openpage)
for child in soup.findAll("h3", {"class": "t"}):
geturls = child.a.get('href')
print urllib2.urlopen(geturls).geturl()
After I clicked "run" Pycharm will return error as follows:
C:\Python27\python.exe C:/Python27/ParseWeb/ParseWeb.py
File "C:/Python27/ParseWeb/ParseWeb.py", line 3
SyntaxError: Non-ASCII character '\xe4' in file C:/Python27/ParseWeb/ParseWeb.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Process finished with exit code 1
It's quite interesting that no matter what I put in line 3, Pycharm will give the error result..
What could be the cause? Thanks!