웹 사이트의 내용을 파이썬으로 긁어 내고 싶습니다. 다만이 같은 :파이썬으로 데이터 스크래핑을 인코딩하기
Apple’s stock continued to dominate the news over the weekend, with Barron’s placing it on the top of its favorite 2013 stock list.
그러나 오류 결과로 인쇄 :
Apple âs stock continued to dominate the news over the weekend, with Barronâs placing it on the top of its favorite 2013 stock list.
기호 " '"표시 할 수 없습니다가 여기 내 코드입니다 : 그러나
#-*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import urllib
from lxml import *
import urllib
import lxml.html as HTML
url = "http://www.forbes.com/sites/panosmourdoukoutas/2012/12/09/apple-tops-barrons- 10-favorite-stocks-for-2013/?partner=yahootix"
sock = urllib.urlopen(url)
htmlSource = sock.read()
sock.close()
root = HTML.document_fromstring(htmlSource)
contents = ' '.join([x.strip() for x in root.xpath("//div[@class='body']/descendant::text()")])
print contents
f = open('C:/Users/yinyao/Desktop/Python Code/data.txt','w')
f.write(contents)
f.close()
, 설정 후 printf의 기능은 유용하지 않습니다. 왜? 그리고 어떻게해야합니까? 저는 Windows를 사용하고 있으며 기본 인코딩 방식은 gbk입니다.
당신이 스크래핑을하고 코드를 게시 할 수 사용할 수 있습니까? –
명세서를 어떻게 인쇄하고 있습니까? 명령문을 인쇄하기 위해 실행 한 정확한 명령을 게시하십시오. 파이썬에는 printf 함수가 없습니다. – stackoverflowery
[Beautiful Soup] 시도 (http://www.crummy.com/software/BeautifulSoup/) –