# -*- coding: utf-8 -*-
from pyquery import PyQuery as pq
from urllib import urlencode
from urllib2 import Request,urlopen
def sendRequest(url, data = None, headersOnly = False):
headers = { 'User-Agent' : 'Mozilla/5.0 (X11; U; Linux i686; en-US;)' }
request = Request(url, data, headers)
return urlopen(request).read()
resp = sendRequest("https://foursquare.com/v/rivers-edge-cafe-- morrison/4c1907776e02b7132eae627b")
print pq(resp)("#venueCategories").text()
输出应为 Café、Burger Joint、Sandwich Place 但出现异常:
Traceback (most recent call last):
File "unicodeerr1.py", line 11, in <module>
print pq(resp)("#venueCategories").text()
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 3: ordinal not in range(128)