1
test.txt에는 2 줄의 문장이 있습니다. 코드에서왜 HTML 코드를 표시 할 수 없습니까?
The heart was made to be broken.
There is no surprise more magical than the surprise of being loved.
: 나는 HTML 코드를 인쇄하려고
import urllib2
file = open('/Users/name/Desktop/textfile.txt','r')
data = file.readlines()
file.close()
countline = 0
for line in data:
countline = countline + 1
line_replace = line.replace(" ", "+")
line_url = 'http://sentistrength.wlv.ac.uk/results.php?text=' + line_replace + '&submit=Detect+Sentiment'
requesturl = urllib2.Request(line_url)
openurl = urllib2.urlopen(requesturl)
readurl = openurl.read()
print readurl
. 텍스트 파일에 문장이 하나만있는 경우. 다 잘 작동하지만 텍스트 파일에 2 문장이있을 때 오류가 있습니다 (두 문장의 HTML 코드를 표시하고 싶습니다.)이 문제를 해결할 수있는 방법은 무엇입니까?
가 오류 : 어쩌면
URLError: <urlopen error no host given>
http://docs.python.org/library/urllib.html#urllib .urlencode –
'line_url'은'\ n'을 포함하고 있습니다. 그 변수를 출력 해보십시오. – Levon