当前位置: 首页 > 工具软件 > tagmusic > 使用案例 >

scrapy各种请求参数

费德宇
2023-12-01

get请求 查询字符串

1.使用FormRequest

    start_urls = ['https://careers.tencent.com/tencentcareer/api/post/Query?']

    def start_requests(self):
        for url in self.start_urls:
            params = {
                "timestamp": str(int(time.time() * 1000)),
                "countryId": "",
                "cityId": "",
                "bgIds": "",
                "productId": "",
                "categoryId": "",
                "parentCategoryId": "",
                "attrId": "",
                "keyword": "",
                "pageIndex": "1",
                "pageSize": "10",
                "language": "zh-cn",
                "area": "cn"
            }
            yield scrapy.FormRequest(url, formdata=params,method="get")

2.urlencode

	from urllib.parse import urlencode
    start_urls = ['https://careers.tencent.com/tencentcareer/api/post/Query?']

    def start_requests(self):
        for url in self.start_urls:
            params = {
                "timestamp": str(int(time.time() * 1000)),
                "countryId": "",
                "cityId": "",
                "bgIds": "",
                "productId": "",
                "categoryId": "",
                "parentCategoryId": "",
                "attrId": "",
                "keyword": "",
                "pageIndex": "1",
                "pageSize": "10",
                "language": "zh-cn",
                "area": "cn"
            }
            url = url + urlencode(params)
            yield scrapy.Request(url,method="get"

get请求 payload

payload= {"page": 1, "size": 15, "searchKeys": ["companyNameCN", "companyNameEN"], "isSearch": False,
                    "selectAndMap": {"categoryId": [id], "boothAreaSearch": [], "boothNumber": []},
                    "orderModel": {"order": "asc", "properties": ["companyNamePinyin"]},
                    "selectOrMap": {"isPovertyAlleviation": [], "isFirstJoin": [], "isContinuousJoin": [],
                                    "isBrand": [],
                                    "exhibitorType": [], "productTrait": [], "isCfWinner": [], "tradeTypes": [],
                                    "isGreenAward": [],
                                    "isInvitationAward": []}, "searchValue": ""}
            yield scrapy.Request(url,
                                 method="get",
                                 body=json.dumps(data),
                                 )
 类似资料: