谁敢想这个报错竟然是因为文件保存路径里有中文???

事情原本是这样的:

文件保存路径是D:\install\desktop\毕业论文\毕业论文脚本\爬取动态页面test.py

运行如下代码

header = {"user-agent":"Mozilla/5.0.html (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.html.2171.71 Safari/537.36",
"b0ac81f5e719b7337916": "b7c1b735dc17af6a19bf7e3353629029d9a266c5c8ee716a2333115dda97f3f294a28d8a90873175415f7a6bb04396d0d61fef90e5f27e539eef656219e41da4",
"cookie": "UM_distinctid=17d32f735c3117-0eb7af4bd329d1-978183a-144000-17d32f735c42ea; zg_did=%7B%22did%22%3A%20%2217d32f76d7b6e4-0f4e53f49fe58-978183a-144000-17d32f76d7c66f%22%7D; zg_294c2ba1ecc244809c552f8f6fd2a440=%7B%22sid%22%3A%201642490147687%2C%22updated%22%3A%201642490147694%2C%22info%22%3A%201642490147692%2C%22superProperty%22%3A%20%22%7B%5C%22%E5%BA%94%E7%94%A8%E5%90%8D%E7%A7%B0%5C%22%3A%20%5C%22%E4%BC%81%E6%9F%A5%E6%9F%A5%E7%BD%91%E7%AB%99%5C%22%7D%22%2C%22platform%22%3A%20%22%7B%7D%22%2C%22utm%22%3A%20%22%7B%7D%22%2C%22referrerDomain%22%3A%20%22%22%2C%22cuid%22%3A%20%22undefined%22%2C%22zs%22%3A%200%2C%22sc%22%3A%200%2C%22firstScreen%22%3A%201642490147687%7D; QCCSESSID=cee0044330a4749ba1d302c342; qcc_did=a979519c-8302-45ba-835e-bfedd4f45383; acw_tc=7dd2e59516457728910618032e8c882854baac1f8c7cb2a3cafa0b8807; CNZZDATA1254842228=795313280-1637228350-https%253A%252F%252Fwww.baidu.com%252F%7C1645772111",
"referer": "https://www.qcc.com/web/search/trademark?key=%E7%BA%BA%E7%BB%87&type=zhuanli"}  

qcc = requests.get(
    "https://www.qcc.com/api/bigsearch/zhuanliList?isAgg=true&pageSize=20&searchKey=%E7%BA%BA%E7%BB%87",
    headers=header,
    ).text
print(qcc)

报错:

所在位置 行:1 字符: 2
+ [?1;0c d:; cd 'd:\install\desktop\毕业论文\毕业论文脚本'; & 'd:\install\P ...
+  ~
"[" 后面缺少类型名称。
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingTypename

解决方案:

将文件保存路径改为D:\install\desktop\test.py

成功

Logo

鸿蒙生态一站式服务平台。

更多推荐