Python 值问题:SyntaxError:无效语法

1 投票
1 回答
1033 浏览
提问于 2025-04-16 09:42

我在学习,所以请多多包涵。

我在这里做错了什么:

#!/usr/bin/python3.1

import urllib.request

page = urllib.request.urlopen ("http://au.finance.yahoo.com/q?s=AUDUSD=X")
text = page.read().decode("utf8")

where = text.find('Last Trade:</th><td class="yfnc_tabledata1"><big><b><span id="yfs_l10_audusd=x">')

start_of_us_price = where + 80
end_of_us_price = start_of_us_price + 6

us_price = text[start_of_us_price:end_of_us_price]

where = text.find('Trade Time:</th><td class="yfnc_tabledata1"><span id="yfs_t10_audusd=x">')

start_of_trade_time = where + 72
end_of_trade_time = start_of_trade_time + 11

trade_time = text[start_of_trade_time:end_of_trade_time]

print ('The price is $ 'us_price' as of 'trade_time'")

1 个回答

4

最后一行应该是:

print ('The price is $ ', us_price, ' as of ', trade_time)

考虑一下这个内容,帮助你更好地理解:

>>> x = 3
>>> print('The value of x is:', 3, 'Yes!')
The value of x is: 3 Yes!

撰写回答