首页 > 其他分享 >scrapy post请求练习

scrapy post请求练习

时间:2023-10-05 16:22:42浏览次数:35  
标签:baidu self 练习 parse scrapy post response

import scrapy
import json

class TransferpostSpider(scrapy.Spider):
    name = 'transferPost'
    allowed_domains = ['fanyi.baidu.com']
    # start_urls = ['http://fanyi.baidu.com/']
    #   post请求不能用默认生成的,因为不能携带请求参数
    # def parse(self, response):
    #     pass

    def start_requests(self):
        url = 'https://fanyi.baidu.com/sug'
        data = {
            'kw':'final'
        }
        yield scrapy.FormRequest(url=url,formdata=data,callback=self.second_parse)

    def second_parse(self,response):
        content = response.text
        res = json.loads(content,encoding='utf-8')
        print(res)

  

标签:baidu,self,练习,parse,scrapy,post,response
From: https://www.cnblogs.com/sgj191024/p/17743480.html

相关文章

  • get请求和post请求的区别
    一.GET和POST是什么?HTTP协议中的两种发送请求的方法,本质上都是在进行TCP连接.二.GET请求和POST请求的区别是什么?GET请求参数是通过URL进行传递的,POST请求的参数包含在请求体当中。GET请求比POST请求更不安全,因为参数直接暴露在URL中,所以,GET请求不能用来传递敏感信息。GET......
  • 读书网入库练习
    settings.pyDB_HOST='localhost'DB_PORT=3306DB_USER='root'DB_PWD='1234'DB_NAME='guli'DB_CHARSET='utf8'#Configureitempipelines#Seehttps://docs.scrapy.org/en/latest/topics/item-pipeli......
  • 函数练习错题
    A函数的返回值不能一次返回两个数例如inttest(){}return3,4;           intmain(){          最后的结果不是3,4而是4,因为这是个逗号表达式,整个表达式会从}intret=test();     左到右依次计算,但是最后的结果只会返回最......
  • c语言代码练习17
    需求:判断用户输入的一个数字是否为一个素数。#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>voidayue(int*pinput){inti=0;for(i=2;i<*pinput;i++){if(*pinput%i==0){printf("您输入的数字不是一个......
  • c语言代码练习--函数
    函数:一,概念:1,在计算科学中,子程序(英语:Subroutione,procedure,function,rotine,method.subprogram,callableunit),是一个大型程序中的某部分代码,由一个或多个语句块组成。它负责完成某项特定任务,而且相较于其它代码,具备相对的独立性。2,一般会由输入参数并有返回值,提供对过程的封......
  • python练习3| 测试类
    点击查看代码#shopping_list.pyclassShoppingList:#shopping_list是一个字典结构def__init__(self,shopping_list):self.shopping_list=shopping_listdefget_item_count(self):returnlen(self.shopping_list)defget_total_price(......
  • scrapy电影天堂练习
    movie.pyimportscrapyfrommovieProject.itemsimportMovieprojectItemclassMovieSpider(scrapy.Spider):name='movie'allowed_domains=['www.ygdy8.net']start_urls=['https://www.ygdy8.net/html/gndy/china/index.......
  • c语言代码练习16
    //计算a,b间的最大值#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>intayue(inta,intb){if(a>b){returna;}else{returnb;}}intmain(){inta=10;intb=20;intmax=ayue(a,......
  • c语言代码练习15
    //使用togo跳转代码,阻止关机#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>#include<string.h>intmain(){charinput[20]={0};system("shutdown-s-t60");printf("注意!注意!,您的电脑将在1分钟后关机,请输入:我是帅哥。才能取消关机。\n请输入:......
  • c语言代码练习14
    //设计一个猜数字游戏,需要提示猜大了还是小了,直到猜对为止#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>#include<time.h>#include<stdlib.h>voidmenu(){printf("###############################\n");printf("######1.play0.......