import requests import time headers = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36', 'referer': 'http://fund.eastmoney.com/400015.html?spm=search' } params = { "scheme": "http", "host": "api.fund.eastmoney.com", "path": "/f10/lsjz", "query": { "callback": "jQuery18303118265739643302_1690164521076", "fundCode": "400015", "pageIndex": "6", "pageSize": "20", "startDate": "", "endDate": "", "_": "1690165052233" } res = requests.get( 'http://fundf10.eastmoney.com/jjjz_400015.html.api', params=params, headers=headers) LSJZ = res.json()['Data']['LSJZList'] for i in LSJZ: print("单位净值:",i['DWJZ']) 没有出现预期结果,但是出现了下面的提示:File "C:\Users\刘岩\.spyder-py3\temp.py", line 23 res = requests.get( ^ SyntaxError: invalid syntax 如何改正?
时间: 2023-08-13 20:03:32 浏览: 130
你的代码存在一个语法错误。在 `res = requests.get(` 这一行上,缺少了一个右括号。
要修复这个错误,只需在该行的末尾添加一个右括号即可。以下是修正后的代码:
```python
import requests
import time
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
'referer': 'http://fund.eastmoney.com/400015.html?spm=search'
}
params = {
"scheme": "http",
"host": "api.fund.eastmoney.com",
"path": "/f10/lsjz",
"query": {
"callback": "jQuery18303118265739643302_1690164521076",
"fundCode": "400015",
"pageIndex": "6",
"pageSize": "20",
"startDate": "",
"endDate": "",
"_": "1690165052233"
}
}
res = requests.get(
'http://fundf10.eastmoney.com/jjjz_400015.html.api',
params=params,
headers=headers)
LSJZ = res.json()['Data']['LSJZList']
for i in LSJZ:
print("单位净值:",i['DWJZ'])
```
修正后的代码将不再报错,并且可以正常执行请求和打印单位净值。
阅读全文