vickujiang 2021-06-21 17:26 采纳率: 20%
浏览 94
已采纳

爬虫错误TypeError: 'str' object is not callable

代码如下:

import requests
import re

url = "https://www.haagendazs.com.cn/products/cake"

headers = {
    "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.54"
    }

dat = {
       "actionsHistory": [{"name":"Query","time":"\"2021-06-21T08:05:16.209Z\""},{"name":"Query","time":"\"2021-06-21T08:00:20.250Z\""},{"name":"Query","time":"\"2021-06-21T07:59:15.402Z\""},{"name":"Query","time":"\"2021-06-21T01:31:28.699Z\""},{"name":"Query","time":"\"2021-06-21T01:28:51.734Z\""},{"name":"Query","time":"\"2021-06-18T04:35:08.934Z\""},{"name":"Query","time":"\"2021-06-18T01:19:52.768Z\""},{"name":"Query","time":"\"2021-06-17T07:11:13.747Z\""},{"name":"Query","time":"\"2021-06-17T06:34:19.443Z\""},{"name":"Query","time":"\"2021-06-16T09:48:59.447Z\""},{"name":"Query","time":"\"2021-06-16T09:40:35.778Z\""}],
       "referrer":"",
       "visitorId": "8fa6a9ab-a561-42e1-ad19-f7795d9826bb",
       "isGuestUser": "false",
       "aq": (("@z95xpath"=="C378A96BB2E74B5FBDBCFFD40F519A15" ("@gmicategory4"=="所有蛋糕" "@z95xtemplate"=="2B0F0724046E49E888522B9DA9E585F7"))) ("@syssource"=="Coveo_web_index - brand-platform-prod"),
       "cq": ("@z95xlanguage"=="zh-CN") ("@z95xlatestversion"==1),
       "searchHub": "HaagenDazs-CN",
       "tab":"cake",
       "locale": "zh-CN",
       "pipeline": "HaagenDazs",
       "maximumAge": "900000",
       "firstResult": "0",
       "numberOfResults": "10",
       "excerptLength": "200",
       "enableDidYouMean": "false",
       "sortCriteria": "relevancy",
       "queryFunctions": [],
       "rankingFunctions": [],
       "groupBy": [{"field":"@gmicategory3","maximumNumberOfValues":"6","sortCriteria":"occurrences","injectionDepth":"1000","completeFacetWithStandardValues":"true","allowedValues":[]},{"field":"@gmicategory4","maximumNumberOfValues":"6","sortCriteria":"occurrences","injectionDepth":"1000","completeFacetWithStandardValues":"true","allowedValues":[]},{"field":"@gmicategory5","maximumNumberOfValues":"6","sortCriteria":"occurrences","injectionDepth":"1000","completeFacetWithStandardValues":"true","allowedValues":[]}],
       "facetOptions": {},
       "categoryFacets": [],
       "retrieveFirstSentences": "true",
       "timezone": "Asia"/"Shanghai",
       "enableQuerySyntax": "false",
       "enableDuplicateFiltering": "false",
       "enableCollaborativeRating": "false",
       "debug": "false",
       "allowQueriesWithoutKeywords": "true"
       }

#发送post请求,发送的数据必须放在字典中,通过data参数进行传递
resp = requests.get(url,headers=headers,data=dat)

#print(resp.text)

print(resp.text) #将服务器返回的内容直接处理成json => dict
#a = resp.json()
#print(a)

resp.close() #关掉resp

  • 写回答

1条回答 默认 最新

  • weixin_45864635 2021-06-26 21:21
    关注

    resp = requests.get(url,headers=headers,data=dat) 用的是get

    resp.close()做什么的? 

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条