1
這不是我的代碼,它是我在互聯網上發現的執行(或應該執行)我想要的任務的模塊。爲什麼在Python中這是「無效的語法」?
print '{'
for page in range (1,4):
rand = random.random()
id = str(long(rand*1000000000000000000))
query_params = { 'q':'a',
'include_entities':'true', 'lang':'en',
'show_user':'true',
'rpp': '100', 'page': page,
'result_type': 'mixed',
'max_id':id}
r = requests.get('http://search.twitter.com/search.json',
params=query_params)
tweets = json.loads(r.text)['results']
for tweet in tweets:
if tweet.get('text') :
print tweet
print '}'
print
Python的外殼似乎表明,誤差爲1個線路I知道很少的Python所以不知道爲什麼它不工作。
您正在使用哪個版本的python?如果> = 3.0,使用'print()'(它現在是一個函數) – lifetimes 2013-04-28 16:36:52
那個排序..那個位。現在我得到「ImportError:沒有模塊名爲'請求'」 – user1765369 2013-04-28 16:39:58
檢查[這個答案](http://stackoverflow.com/questions/11994337/need-help-installing-requests-for-python-3),看起來喜歡它可以解決你的問題與'請求'模塊。 – raina77ow 2013-04-28 16:42:26