当前位置:   article > 正文

request.session使用途径

request.session

AES网页端javascript使用,和在python中的使用区别。
字符串转bytes的函数–encode
bytes转字符串的函数–decode

#使用session发起请求
session=requests.session()
session.post()

对比
requests.post()

requests库的session会话对象可以跨请求保持某些参数,说白了,就是比如你使用session成功的登录了某个网站,则在再次使用该session对象求求该网站的其他网页都会默认使用该session之前使用的cookie等参数

尤其是在保持登陆状态时运用的最多,在某些网站抓取,或者app抓取时,有的时强制登陆,有的是不登陆返回的数据就是假的或者说是不完整的数据,那我们不可能去做到每一次请求都要去登陆一下怎么办,就需要用到保持会话的功能了,我们可以只登陆一次,然后保持这种状态去做其他的或者更多的请求。

  1. from Crypto.Cipher import AES
  2. import execjs
  3. import requests
  4. #password = b'jo8j9wGw%6HbxfFn' #秘钥,b就是表示为bytes类型
  5. #iv = b'0123456789ABCDEF' #需要加密的内容,bytes类型
  6. ##aes = AES.new(password,AES.MODE_ECB) #创建一个aes对象
  7. #aes = AES.new(password,AES.MODE_CBC,iv)
  8. ## AES.MODE_ECB 表示模式是ECB模式
  9. ##en_text = aes.encrypt(text) #加密明文
  10. ##print("密文:",en_text) #加密明文,bytes类型
  11. #en_text="95780ba0943730051dccb5fe3918f9fe4c6612ab8a332ee7d1067088471faa620510faf3c14d9cb03647e2bbf06f1b7c990f969cf20f58a06049376335dcd53ee60d585c68072617b4c57a2242d5eb6e6bd893c75fadee251a04e36997002bf38728a06de03afc4576627741cd1e488eed9a41cb4a21832d8d435a19aa315af2c088789869223a037f45be312d5505e1bdb3f90bb417bf73279a9b59871720d43e890ff077785ba05edce69cddaa742959ab1963145fe34343493196c1b092fc223e05e741d4553a247ef549613ec91860ff87617cebe4024aa83a42e25cdfcc7d5df4b383c0def42db46e4e62e8909215860c83cdb5a2b7093c5052bf713baa7f6a19aafe79db75b1d40fac19fd1de6ebae16a413f0b722451e17f3d839a971f324f15b2868ee201e4883bf54c234bf8d22cf8c304bffb7231f8d4a39e488ac53dcf2c144da4cc23eb7e82a5fa6953385fe8e915ea7c7cc32d2025746adf5650b46852c99dba4d4d76511221416801c8a1fc4b581c5ae38cb499202f026321a4152c9fe91cf1521546bad6b4dfa40395794cd4840fd329d446cba0287634bbd98ac5c14c4ee6ff82460cede9d917bc867cc32ec726882b074fccc1acd2ab851972ff5b15afb2d88effd092b2a7b5d1533c8c62a9c804127bb6bbadabaee1f87d7d73fc52545e422c00b5cf20b97e558bd68e1aa84f027b9134fa496fb12c20ecd6e360e53148431d8f2508fbf8eb019019f613826c1c88de0e117962ff57ab0e847619fc1ae8ca393677902a1d00d8f2299b7b07c9fab484dc6089c2f2840a87398093f8030b81d9678efb908d4392045a06f91b5392b93c215a7befd31364ab7399932c2cd715d8759adc116f320f54ee9ebebe8baf58aecd9a893c72a6a2885274f87a277df835df60386882f51f88e85765121cf0ef9f986712acef14c4ba2592e8c277e439df94233acbc1102d1b12242c0502208c08ac527ea8ca8515db1f8df59d1a9608bbd44e1702733764faf291c4c11ccb0094c4ef35082ed500d16d97c2d333a20c268f179fc0065c667844dcd07bd9efa2acb0a809c90459c19cb8c4dd0470b6d4712fd38ae258f3dae043797a1d7eb3688d9cc71a64f14d51a5e50edc13a0196c6212857d87d7e687d2fe39be7fd8f42162d18cd61a34b5765279f7dd2e6aba03aa43b8204a427cc794ca9e6e12f2c693b5e59fe1075757f80a9aa3e91a70811c0bbe31ced6a4fb671d7c0ca9d8fc1afb4a21a88d82495265ac917492125263218146303d6d7c020ca9b0d4ab339e53f33de8f258cc1f407d8abb83d174ad7ddf0cf216fb31b208422c411dedea437503e8f519c8aebd10a752d07eee70fcfd57b98d0742352ab569d4fd9a7da2f11677449166d0cb62bdc598caeb7c9cea1d0c37a3bc99c3ce8d04cd126aebadbb42f208d8128f5d2915c2b90281adea320ca09ec3d235563de80cabfb867aabddb3957e8ba73c9d2b7c175f89170d220813121e7465c9aaa8ea8ff064e523125276c1d17b47d3fa3452de0fbe3e8673a4f02ee5138cc7f7366b75360b40d8fb6bf2c2ace4504d0da530026b04c9519a5f3989f44f19d3a97022dd22147b5bd4d1033d04bf1bb45e55393a98ef6a7cc7666d18170107a0b76e8b8e6175f78be5e9dbc983d396168910edd2ffb156a9935163a2896db46f9204b7de826a547507d1e3aede65c3f7d012c9ddccfe97e3f333da7c29f95cec5b9a44d23934c51d5681e6e53c51cdc94d9b325d4b6e831784f7ecf4e73856502c69639b0b4f87bd292e0dde5d8098680c6426d2ff304902d5a549e4afe51f687e9e3d88f2662dc8bf307305e30e4105c66ec969826fd5b1111d03a3ab850095bf32e38058fce25b7bc2f17afb49d699b2380821cecb796ae6b35d68e285fa9dd06546858d1aad39a1b6d08edb52a03fbe257ff7813fb619bf469fc3d880223b05c6fc7bed39e590f46077a7aad98952521cc6e97100701cdc9e364b1e3b538f67809bf29025489fbeb2a41f0d0bc70f2b2351b20d39038bec4b5acc8777d6aebbf18cc430af7e2f4f9c7374649dd6a87263f4d458fab08dc5b221433adcf7570534a593857c4597a5a40ef128d21e98c3a4fdeee98de6fd49f6924048a094a42acef925178c794bffb9c26fca0416fd4cecb2ea428f2e013023f410279bc793a46a9f40fc685b1eb30c35b536cea5aca25cdbd83eb17bd640d98cd36a7f127737a491462d1cd0e1c06e103d86c685cb42f35f2680beff343327286be2edda75c702bdc41c884c90504f79cb1ed1dfdbf642c7d002d294f64bb253c92ebf6119931cf41731e9aabf96d33489b28bc21d48f06970289b3d7335ad398b179722c31023a1f3c356601e2b4eabfc763dde95bdde68be5abec0e30d25c21709771f6bc00ed3e00aa70fb4fc410b65fcaa93a533da7bc415c68da41d5e27982860c8e3d454fcd9749412248037bec2a15dbe9785a0a7d4e04a0f787b91a829226d169f7b8c8eef04febe9c8e8f03c89eb0f4fdf4c163e707d9aa8f9b4daab829fccf8a2d2c578d49fc5839360f5662221fada5e87560e06278d5a2ecc3f356a6c0ad9864d8b860e8375a04334a36d3898f8e9b9caf9b4a8ed5739e40b34ca526aec11931403a0d07de51ced53173fbe6e633dc72eb622b1f2a6baa6d21a03271728d644192661a6922cf348abdad611ced66480fbe422427fcb1b77008898e16b9445bb57a187bd5b2e27a2453a707a01d98ad92473f1157cc5a5cad8fbb58ec0972d0fdd1a17a03c9c63e2ed05640dcdf24b9b498ad91b3fc1fe1375e3f340059638c485187e9c6f4ffdfa29931737d1c5d64307665a8008d9b7436ad33f427023a25f7b53b7d1d568536f50ef39b9be227f888b8750db0f37950eed69f412f8a38fbb4d5c785625838c85e976bc92ca958235b0e0c3f8c7c4c172e67e6e21e5febb0468b8fff5ce2eb4fedf6680b0bbe8b5e702538d1648be76acf4d03c152f3f0839103145e29fb9f9f186ec77052b41d3a8944afd7fbdd9fc4e9473c12ae6e451439a315471c71a750b4d26169216a09656123dbec9c7a2ff14af3210006635f89d64ecd8df4d2f97bf2aeb11d1a8eb1f448a19d344315e0dce9f2d395726dc9edb573bbbcc352c314752c72e40d685ce8f057db35f89cf5100183cf71f54f8b3b1b9c31ab1812ed4bc610f69534986b71e705b3a47a13fa0cd65e733c2b21f9765bfd81750399fb8cf0ab9db84b663440cf5ac1d7aecb0fc49f9f07743cbc0a43a618af2419fc132784aca159969581810c278a7a3c4de042da685b240838e8261f1fe8c0da56a6fb52899b28a3509a8e285a153473623cdc16fce4f432d9e49fd05af894a954b696c2dc1fc6892be4e71f263f7326c0f92a28ab53f6ed55f3db3d4407f4ce617574888b329fc5541d5f1d8d182627b06663cebc53f668ffffb15b92602e594c2846cf8f0af2cec185ab0d907e85b6cb0ed0372d4b933f8998e037e5e03c7415b74929e6c34792086393aaa5b8da7acb21c54ee0f8f3835745b5fedfceee07a81b1cbfb2ba96f9cd4e376f98d63048ebf6405f35eb9bf1f4fbecf0246dcf6ab6d63b326593889b066dedd68e743d4af97c2974966d48c4f2e67654034223ab53061d7e4255973737ef79447a5706c5e4f8d6cafbdf62cab406d33fe490f31cd456b76e111615ef6607c16c4b34a5c57ff17a6979a5bfbe031176cd2c06eefaef7a1f8b0e049ca2e58ae8df6f55c4ba9b15de21326a4078ac5ec5c877e30931ec2ac3717c2089f083b7f9759e1ed4fa699249213db363c277f081e7d4f013966a7c2e1e8bc2a43ad210fcf37296162b2dcbec3a7caee1646978822ef5e6ee0a53dac50860e8b5cec40cb3530fd2783e75720e20de8538f233d9d49e1578d36980264fbe4d13b741ae237353e1d3b315bf1115845bc7997181de5e5ca3e077feb9e209af65426126836f6beca21fe134a5afc11d0edc9f0e6bc4865b339e390b2e953d72accf8bcdd2c3adf6910dfd247c6da32d8663469597ef9326ab020ffda0d6f6aa798e6aebfd3d4a9d95918e8ad4d68604b6bdafd75e3d383a56a1a79d9bda1cb2a65e5f35eee8cd9b34cf3828f36ace68fe1af217bddcf6ed1792d831033e30dcbee9bc30a823404704bdf3263bbc9a9dbbe9fb3af84f21a37a5db4ea3891feae8aa5c1ca175b11f33b3e6db0e68c47e311b849c926a0f58abc76e272f90a6fbd3eb9e9e676e1908cb89bb3ffb6e8fc350f80fdb473da00a06f5d0b41c8444dca53aa5ae76332ec8b2930ee5efd719a932dc63d9ae4883230de9dff022cdfe1d37ce76ff44bb56fb481b27e33ced6d43540f25b0e7551ff6071d8879fa7ebf5c0e3d51ca046af46a89685ff0209b86e33bd48d102458de4f29ebea7850854dfb57fdc7949310e945e992916a5b9a06e83cbeeeee1d7068bbe8b8f223e72be3c819f59d6df5858d57915b0dc331524dc8ba29d19298ee284b2724316bd60c7799e9a3eed2223ccebfffefe95ad063664adb51aec570824aec2e75b7fa2f95c666c96421038e0ba993bbf1e1c73daf80860ef5b5566078d398845ba569779570de6960efd344106100ec20f08ac6a7d6882b84abc8a9301f39485262edcf937bf97b947a6698f1bae1567b1d4eebc8e29c67fd5db9d706d0794f18ebe96029a24d86c5f0cc8c4c31e967d1b0d86793b1ada17c08cea5b8061cf7b9a9aaeff46251a61aa9e3c968fe167cee02edbc433b5d14ce560469cfd5cc7ac253b2a903dc8e7eaa57187f5c4eb64938ecf379b1857b6b091d411dfc76394bb5cabcfe127aca46aa602b0f2e119b12e7af0d6ae3741bd88146c2fbaf9c1fd949c5f4be35a41dfef2d0c8e38abe8b370e663859c368abcb8fa02649616c0fef683906e7036f5c793c8f9bfca9b8aeb3ee55a27fb75989e2a98e18dd4cd7c1a5cd311aaf9f6c8d33b78ab93adee7db4f55f258d1f1c2f14650ef81ca5737f9d9adbd36dbabc4876af07fc33297c2e2577341e195cea1c00948fbbf67a58530546bb3bc55f142e18343d8ab120ef4e0079bdf2ee9b81c352ab3a2fdbe092178293e201c12876a48f9086c5f392554234c5569a82375b1a79de9b2a4585294d00671757788a05f8ef47662d7ffefa8d4e2e9f1c8d4b14e13323a941d528f6477b400e623d25bcfc75812787d202a094a64d0f9e7899886c4a9db170713a1fd188ec002e499d0605765225e677fa45b5a705f2d3fd03648a8b90b6af6cc580583f109e4653a4a2a955e680db0b102965c5cb9c76027b68ffbb1a82cf92f3a5f35d0317e7a5b8024f5914b9be4d3f09dd0ac6907e26a832dac0350968b88e75fb3eac81ba2f69c1cf23ba4be73f44abac3d529987ac90a3b6710d466d184c94473160d54c7b549813c774bd9c3308d7b47a2967061169162d2b385899b9e45192c452ca724caee806f17aa5685fc97361e58accadeb6a12629f65fdf4ed2f0ce02e65fd75333fb944d57829881d35df9a8b3b7223ae4c6eeaff9ce1b6b03bfd86bfa359b8befb9ea8fa2ec57cf758758a2f7e731f6e22d9d7747dc8a17159ec3df596832c731a71be20a8b6120a5b022a8cddbe39cdd3fb4a4b09549fbd329819e0a96f381f885adb07fbb9839d6be3d5eb2a6368d3918f81bf990f6c539841e6d872d5e040fd4d7fe1bb4a548cf012518bee2973e01da600028adde3e5531979ca4638bb3e2beb37c6c66389d2f6333395e152aa5edbc48ede079c3eea19e3139d07b20fca904bb346f2c924fe0b3ce0f63db605aa0b6e96f05b81634900db36b3dc91772e0b45e63c0da9c47046be59de81868610a900182d7cd8e19675df7e754f80fd3145e4e29c652d0da95ce8d6d4e35b701"
  12. #den_text = aes.decrypt(bytes.fromhex(en_text)) # 解密密文
  13. #result = str(den_text, encoding='utf-8')
  14. #print("明文:",result)
  15. token_url = "https://dict.cnki.net/fyzs-front-api/getToken"
  16. translation_api = "https://dict.cnki.net/fyzs-front-api/translate/literaltranslation"
  17. UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
  18. session = requests.session()
  19. headers = {"User-Agent": UA}
  20. response = session.get(url=token_url, headers=headers).json()
  21. token = response["data"]
  22. print(token)
  23. payload = {
  24. "translateType": None,
  25. "words": "MQcn3v-VTnXx3D5RwDSn8A=="
  26. }
  27. headers = {
  28. "Token": token,
  29. "User-Agent": UA
  30. }
  31. response = session.post(url=translation_api, headers=headers, json=payload).json()
  32. result = response["data"]["mResult"]
  33. print(result)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/802772
推荐阅读
相关标签
  

闽ICP备14008679号