You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python网页爬取报错SyntaxError: positional argument follows keyword argument求助

解决SyntaxError: positional argument follows keyword argument错误

这个错误本质是函数调用时参数顺序写错了——Python要求先写不带参数名的「位置参数」,再写带参数名的「关键字参数」,反过来就会触发这个报错。

举个网页爬取场景里的常见错误示例:
比如你写了类似这样的代码:

requests.get(url='https://rokomari.com', '/books')

这里url='xxx'是关键字参数,'/books'是位置参数,顺序颠倒就会报错。

正确写法有两种:

# 写法1:位置参数放在前面
requests.get('https://rokomari.com', '/books')
# 写法2:全部使用关键字参数
requests.get(url='https://rokomari.com', params='/books')

你只需要检查自己的爬虫代码,找到所有函数调用的地方,把不带参数名的参数移到带参数名的参数前面,就能解决这个问题。

内容的提问来源于stack exchange,提问作者Amar Bangla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 14:30:40