返回顶部
首页 > 资讯 > 后端开发 > Python >Python如何爬取科目四考试题库
  • 261
分享到

Python如何爬取科目四考试题库

2023-06-14 09:06:55 261人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

这篇文章给大家分享的是有关python如何爬取科目四考试题库的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1、环境PyCharmPython 3.6pip安装的依赖包包括:requests 2.25.0、urll

这篇文章给大家分享的是有关python如何爬取科目四考试题库的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

1、环境

Python如何爬取科目四考试题库

PyCharm

Python如何爬取科目四考试题库

Python 3.6
pip安装的依赖包包括:requests 2.25.0、urllib3 1.26.2、docx 0.2.4、python-docx 0.8.10、lxml 4.6.2

Python如何爬取科目四考试题库

谷歌浏览器

2、目标网站及请求分析

驾驶员考试网站

Python如何爬取科目四考试题库

        从上图中,可以看到科目四共有1487道题目,为了将所有的题目汇总到一个Word文档中,需要获取到每道题的文本和图片。
        首先,打开谷歌浏览器访问上述网站,键盘按F12,点击Network,点击左侧题目中的向右箭头,一直点击下一道题,不断发起请求,在右侧可以看到每个题目的请求链接中只有五位字符的考试码不一样,所以我们要想办法获取每道题目的考试码。

Python如何爬取科目四考试题库

点击其中的一个请求,在Headers中可以看到题目请求的url网址和状态,在Preview中可以看到题目的相关信息。

Python如何爬取科目四考试题库

Python如何爬取科目四考试题库

        然后用谷歌浏览器打开上述网站,然后键盘按F12,点击sources,点击左侧Page下tk.mnks.cn下的lianxitix下的文件夹,可以看到Exam的相关变量信息,其中ExamCodes就是1487道题所对应的考试码。

Python如何爬取科目四考试题库

var ExamStatus = "200";var ExamMsg = "";var ExamVersion = "20210205090935";var ExamCount = 1487;var ExamCodes = "d704f,bdb25,2d1d4,a9eb5,b0671,9b18f,2b0c4,8f1ec,07f6d,ed8f7,a74a2,46806,faa42,a580e,4fc7a,0fb21,97686,37b6b,c9263,f1b18,79e07,e9c0b,01e28,d345f,fcb88,f1301,75642,2a3b2,f70b6,2993b,b493e,64a3D,c9fdd,21f14,53c76,DDD2d,7f5d0,f8543,ee954,533ba,dcd4a,2c15b,8ac1a,e97d7,10e03,0202c,b109d,ebf95,0f7f1,0bca9,36b59,9eefd,eb795,b2a2b,704ea,856e9,9e92c,e76a1,e3970,c36f5,5a407,ee9d9,aeb78,0a570,bdc91,f8f59,c08f0,bb45b,515d9,b347d,28b17,b3dab,bbbbd,94c53,54a92,f1e50,09587,c7890,7a9b3,354b9,e2803,78c8c,256e7,3a8cc,43137,883e8,4f318,b7641,f3192,5a496,1c1fa,7e43d,a50ed,87ad2,9ea88,c788b,95c60,ca436,007c7,a7057,cab0a,5afed,e32ce,7a961,157f8,fc304,12c14,179bc,82e35,863ac,bd2f8,5655d,62935,ff906,8eda8,bad13,8714d,af074,303f7,d4bf5,c78bc,97940,7a981,c87e2,bb685,eb46c,b14b5,7c563,7fc96,e5540,7134a,b85c7,49e6f,9d464,aba3d,60a01,e11cd,bc16b,8ff78,cd884,b2efe,79e6b,dd188,969c7,bc7d9,a856f,c8f91,bb731,45056,658d9,ba732,ebf44,5e748,33f22,58c97,4f211,94644,ee187,881a9,97ecd,6017d,c0b7e,1ad72,5c82d,8146e,3b63a,32c78,c5ac6,9a9ad,9c436,3ce2d,f7e51,b1371,28e07,e39fb,a74c9,2d870,73ccd,e5cfc,04f25,77e6e,9c259,59e10,9f83a,a8d5b,40245,6b3b1,473e8,a215a,b6313,2578c,27457,ca78c,140ef,dbab9,67aac,be529,9fa10,c158f,3e964,5d883,c996e,1e2bb,fc9c7,c096c,07512,683c0,ac2bf,981ea,54456,5f324,90575,db76b,817db,60ea8,8502e,b30e3,90414,a44b7,87ad5,d6e51,6112b,3f620,d23ee,c3f1f,5c057,aafad,63844,0b51d,51231,6679a,bc264,e1353,97cd8,50512,56ecd,610f0,205d7,ed246,c0b90,c9b5c,6d806,48695,961e8,dec7c,71b2c,6a3c6,02b1d,8635f,b8bc4,73790,0a39e,128be,b6b28,88e4f,542df,60ef6,321d8,9be31,48d07,c007a,aea99,837e2,16d82,b260a,21389,906cb,59cd0,d8d85,2da51,674bb,14ef3,71dca,0634a,893a8,0e0ec,e7ef9,15d22,80b13,436f7,6e7e9,60428,a04f4,efbe5,2e063,6aae7,614f2,a4e14,ab335,0e9e1,f1b88,a30a3,8e766,b2b36,b32a7,208cd,8d6c5,ca538,35b1c,c128c,88bc8,c123a,0ec98,83b56,6641b,b279a,242e0,a14a9,0bed0,9795a,d802e,ab41c,db4a1,e0842,05f62,44840,e79b5,91a1e,69132,bf47f,80796,3cf91,779b3,52c5e,44de9,dcd2f,ceee6,993c9,c4552,2b757,3a24b,0766b,4d6fa,d9703,bda35,3cb4e,eeef6,3cd13,9103a,8fcad,c6424,76bcc,6746e,8022f,ad831,5fef8,53998,abfa9,93c85,f2b94,a34ce,c831f,14088,81cff,c2719,23fe1,e0774,4d34d,e2912,c516b,8d197,8bc73,9269f,3cbdc,05320,e7e31,78e16,b61d6,a8bec,cce92,f68ba,a0252,d058b,f8dde,e1e40,b733e,b812d,aea74,e417f,beca3,f7c37,bff53,a0c66,c87c0,f0175,e996e,f1b8f,b20eb,c5b0f,e72f8,d57bf,fffcc,de5e6,ef8b1,b20f2,e3834,cb709,fc06f,a4af2,e376f,d79a1,acd5a,ba00b,d5399,f8091,c218a,d67d2,a740f,d324d,fa535,a1ffa,bcbed,e7755,cc3f0,aaef0,b6c1d,a3f35,ebed2,f8175,bebd6,cdf38,f8679,ccf4a,f1c28,bf561,b1477,babb5,ac9f8,f2f75,fbc74,c0f8d,c72e1,bc708,d9ac6,ea6fa,da81e,df72f,faa0e,addb6,c8ac1,a8a27,f3548,f634b,ec2cf,a4d17,e68d1,eff90,d51b1,bdfee,e0dc2,e421a,b8a92,e1b62,d01d0,cc671,c153a,fc9cf,df350,d2c22,df916,c5d21,f765e,aa2d4,a9d8d,c2b36,ca016,b4e29,ac2fa,e4599,b83cd,f586d,ef7bf,b0c07,fc6d2,eeec7,e720e,b558e,ef56f,b3353,a6de8,fab1d,c921e,b6a29,a0019,b03ef,cc742,a3d8d,b4e35,e6668,fe71a,fd836,cded9,c458e,d454b,b2f57,deda8,ab459,f47b9,f0356,d2f78,e6b0c,ac32f,f78d5,d1c4e,da652,b391c,a2fc6,a77f4,de655,f8baf,b66e9,c8b74,d1dfa,ee79c,c3612,ec3f1,ea5c6,d0a61,c08cf,d7f50,f2685,ab910,f173e,d1499,ebcdd,f762d,e97b3,a47eb,e32c8,db61e,c8dca,fcfdd,e0051,d40d5,cfec0,f7cf1,af433,e4017,bc343,d5ba9,d60fe,bb346,a1b8c,ab5ed,b65e5,ec1cf,a7798,e6737,ea3b8,e1076,ce973,a5c75,ce15f,d70aa,dbc04,dce8a,b5565,a68f0,abc90,c1792,eddfa,ab24c,ac20a,a732d,e49d4,e7fb1,fface,e48cf,fa808,cc8b2,fe112,bcf86,c0e70,e085b,bc95e,fc890,cf8b5,cac27,c4e9c,ce788,ca5c8,b554b,d68a4,db427,b20b7,be61d,b0fc3,b18a2,c7946,ea80b,abb99,b9529,ddd67,b9d3e,b8b96,fc5da,ec6c4,d5cea,e1a86,f55b7,b4a50,cf3cb,e270a,d15ab,f7603,b0b77,b3cfa,c73e0,519d9,6d9af,ff6ac,0e915,9ac33,d927d,b47e4,f63f1,4e160,c5f3b,616e0,6cd0d,89473,f4f21,9bcb3,2867b,807a8,130fb,12c69,017d6,6aeaa,fe06a,59fbd,4a0ff,d27ca,eb735,819ab,4f065,f4a64,a6615,95ff2,e5b71,2c989,8b864,67974,8109c,a376e,9e031,80cf3,e7b13,084fd,ff06b,2e73a,50e6b,238d6,6e76a,859eb,467bf,21e1a,961a7,bd190,86f9b,93a64,d72d6,b12b0,ca724,46d09,b8699,78c25,a7f66,ffcd7,7b165,04636,5841a,c1cc5,290e8,c97bc,88155,a4330,8619d,9bc46,dbb4a,81427,1fe18,69abd,4639e,31152,3a172,e6d89,65b42,08412,d087e,c6cc0,85d52,ba77a,0afcd,33a5e,b60ef,ca7d7,8e6ac,71375,61b21,eb252,0ad2c,2dd2f,5a7b7,c0fdf,cf98b,38e59,e8b7c,118f9,fd67f,2c3bb,d4024,c4a96,09f62,22173,f308d,df4cc,ce9b0,90577,397c5,fe055,19b64,efa09,10e0c,53c4b,14258,9bbfc,6bb19,0ed7e,38f11,4fa06,e5dd8,cf457,52ea4,38e5c,4193a,9b59f,26352,71e5e,d923d,c204e,7170f,d5470,c16c1,a5b36,51fe7,80b37,44ac6,37b37,1243e,d3937,3e01b,65c9d,3fea6,2a2c3,1cb7a,9821c,7971e,1163c,49c8f,646d7,54584,32bfa,b9ed8,8b4b7,7b211,4b622,69a0d,75b11,45352,44bf2,f7294,f1353,284e5,c00dd,57854,44d40,128d2,2205b,94278,e9c3b,6f533,b6b90,58638,4f718,0f36c,1ac30,34b2f,72e3c,2b14a,574e6,41689,66c69,79bf5,7e87f,8bb46,d1d95,b3c79,0b2b6,95c8c,321df,61c35,d4e94,16c87,e4408,8bd10,003c0,5a1d3,42799,edac5,005e8,cb158,f6bf8,547de,1840d,a2f3b,3d25a,965f0,5bd1b,cf0d7,40922,a579e,aa5be,d9a9d,bc86a,fd8c1,d84cc,e066a,a8c25,edd5e,36d33,2c773,fecd1,f52c9,e32ed,b3cc3,8aaae,1dccc,aa0f0,a73f1,7d027,68418,73131,8e24f,8a579,e6fb8,f1bbf,801c6,d4eb6,e79a0,85d3d,077c8,e001c,45cf4,8362b,c00e3,047f6,e5678,4d14b,c045d,1f4a4,a99b0,1e938,d3633,b84e8,f3c29,2fc4a,195c0,6000b,49b05,0203b,6effd,9a31a,3ba9a,eaa09,f0573,6d220,2fa6c,f9acd,c1cb6,43b6e,fa908,ba1cf,dd3c4,64fdd,d7ddf,e6f82,b4c0a,79d4f,df8c9,9c0a2,b121c,aa5c5,ac2b2,a5fa8,ee70b,56c48,23082,f6de7,d5275,e97d9,4ee52,c8971,c8eb5,927a3,33416,4507d,b5113,e7f9d,853ef,97b3c,3cfb2,fecd3,aa1d3,178e3,10b7d,c8c06,f33bb,e046d,0c159,abf33,0a7bd,a990d,1e31d,daf75,49268,f0e5e,6b4f8,bd4f8,684b6,b2701,9c972,69103,17d69,2ea7b,ce1c0,30081,02465,859de,6b269,307f5,d2870,8ffaf,222a3,183b4,a9bfb,d693a,bc73e,9b2eb,b7749,abf5d,abeaa,8de3b,a1a23,08fb6,52c84,23d21,2ae95,636ee,7cd61,98a4f,f12bb,f5aa6,2566e,b107b,b4fa8,3bff4,a174e,322cf,1eea3,f80c5,a0e5a,34b1f,afa49,29305,9585c,a236a,82381,d7a96,41172,2a1e0,6ce2a,2f303,49452,5f567,e7b8a,edddd,5ec6d,e8369,bea53,7b903,212b0,35f9b,0cc9a,24b24,5cfe9,b78ae,ce597,8bfb9,ac70b,da0b2,e4568,e6786,d5da8,abcda,d85eb,b0fd9,ed9a4,f0b48,bce0a,fdf29,fbefb,ab641,fb21f,d770c,ec608,d6e33,f73e8,c661f,efc46,ba9d4,f911c,ed8bc,ef63d,be67e,c9c90,cfa3e,2a692,88fbb,88658,c0bd1,568f4,2cca3,3cd85,91402,eca62,d4863,70705,d47f6,3b054,29a98,1e3c8,ccc22,fcaa3,43b54,5eaf6,5c85d,dfcfa,6497c,da3cc,bbd1c,62646,212f6,49141,b6396,6bfe9,14b90,47364,8798b,0eec5,83039,8b0b5,f43f7,b2dea,a8723,4e5bd,c741c,33380,43429,503c6,05fcb,70446,35d8c,4d9c9,25e1c,c5ad4,a2372,07ba3,53515,2ddaa,549c1,c92ea,39a17,ea5ef,f7ca4,e1817,86aea,ca38a,243cf,2a4ee,42e8d,09f91,3f35d,11e0b,072c6,73b62,d4333,5b9c6,0b507,f027c,5aea2,e78cd,602cd,c723b,54fa6,9d161,11fbd,fd2e1,6425d,fb2b7,0ea23,368fa,78d15,95162,19158,3bda1,e1861,8f8eb,5cfa8,786db,60697,2048c,c10b7,99425,7e170,44af8,0fa2e,783ba,83705,5c305,85b33,f9b21,4c0b1,f5ac0,5fddb,58158,8c539,252fe,871b9,24fc4,09f74,b9564,a7a67,d5212,657d8,9e71f,d5671,4f2f5,dde4a,d9948,5e4f0,0fce3,30b17,76889,c8367,330a4,2136b,9b3aa,da6f6,03acc,b8b49,9b26d,efb1c,0335b,e1ff8,84748,fc362,bb949,52b1f,d889e,7d679,278c4,1e33a,61585,0e2a8,04ad2,66e1d,35e89,c3f4e,24d88,63e36,a8539,8b54b,99028,4f644,681cc,d4b63,45a57,87437,310a7,26880,a631e,7a736,b2b3f,8af48,ddf01,a1e78,2dd02,90ae2,8ebd5,a922c,34e3a,96c58,1d849,ab04f,d9e12,fdec7,0b9d5,1cc77,6a6eb,76eac,e00c4,1f79d,2568c,060cb,c974f,77894,e3639,99176,08f47,7d3e8,5d5f9,fa17e,21ae2,445f8,4a294,c6cd0,db775,6e474,ecb0a,aa3c7,cf79b,30d3b,376b0,e28bd,0a9df,fc6d8,70456,d7f5e,74deb,bd184,01761,0ab46,9e209,c2780,fae95,efd55,5129f,d981e,b095f,d990a,dca62,de660,a0943,d303e,d3db8,dd9f2,a01c5,e7852,e71e3,f88b3,aed38,e4038,c05db,b4281,bddb4,b1ecf,f74af,e9fcc,d5370,f319a,a4931,b400e,adef2,d3047,eb6e6,a6c84,c769b,b574d,b1277,dbd4c,d8939,b475c,b926d,e4ecd,cf96a,b1460,43831,4be83,ab827,09298,de6ca,39c10,9b2b8,5ff22,48aeb,82f57,7ca7d,b4173,0b0a2,ae848,953e8,de7cc,86e55,109bf,a7f08,55208,1b0aa,db1e7,8ac2e,02a6c,33e3b,7d133,b1c42,fae58,039c3,26425,ecf67,5dd2c,cf4b7,3af32,a1ec0,37572,85680,c331c,27222,f11ad,c619f,ee425,5286a,9f093,d3dcf,80ac4,97e71,d29fa,73988,abce4,c1072,8b749,abb35,e3c04,3ebcf,27a67,1eca2,3ca38,f0d9a,08a0f,6efd4,535ff,b0cfa,2be29,2e6f9,5e5a0,0331c,8797d,42700,b2d3b,ee98d,28198,a2b02,ba561,2dd94,f935c,42380,b5ebc,9887c,9970d,5ce92,7606b,d2f61,4cdcc,e4e52,f9e1f,99047,57680,f08fb,e1603,ff658,1e293,d7b66,b1ed6,94ac8,92d2c,f5541,20a5b,48979,f0bdd,7c362,4fc99,154c4,dfaec,f9a9c,95fb6,b2414,a1a57,b0e99,a8ea1,c28af,d943c,d8e2c,b99f1,b94b8,fa1d8,c4fcc,f8c1b,cb560,a8fdf,b4364,d463e,e9545,f21fc,c720e,c8821,f9f0d,ab201,d9367,f9a18,f7ae4,b415c,dbcd8,a60ba,a195a,ede25,fb8b9,cdad5,f52b0,d000a,f02ff,f898e,b1cdc,b6340,e4fa1,bd39e,a3d71,c79c1,c4a20,ce523,fb29c,eec0c,3576d,41eed,aaba2,c0138,7fd3e,ee164,46c17,8302c,e6b90,fca49,97736,c3502,e35a4,585e2,eee72,ee94f,a2ba8,0a40d,47864,90832,ba75e,4e3a9,07d62,75b2c,76f65,eca2f,b389c,66a17,b01bf,c5098,d62fa,89687,94f69,6da2f,dc76e,6c125,6802e,a69a4,96eed,c12c3,d40fe,d8dee,e95ce,f8a38,dbd1f,f7681,d825b,c4903";

3、Python代码

完整代码如下:

import requestsimport timeimport urllib.requestimport docx#创建内存中的word文档对象from docx.shared import Ptfrom docx.enum.text import WD_PARAGRAPH_ALIGNMENTdef download_img(img_url,imgname):  request = urllib.request.Request(img_url)  try:    response = urllib.request.urlopen(request)    img_name = imgname+'.gif'    filename = "D:\\Program Files (x86)\\PyCharm CommUnity Edition 2020.1.1\\PaQukemu4tiku\\folder\\imgpath\\" + img_name    if (response.getcode() == 200):      with open(filename, "wb") as f:        f.write(response.read()) # 将内容写入图片      return filename  except:    return "failed"ExamVersion = "20210205090935"ExamCount = 1487ExamCodes = "d704f,bdb25,2d1d4,a9eb5,b0671,9b18f,2b0c4,8f1ec,07f6d,ed8f7,a74a2,46806,faa42,a580e,4fc7a,0fb21,97686,37b6b,c9263,f1b18,79e07,e9c0b,01e28,d345f,fcb88,f1301,75642,2a3b2,f70b6,2993b,b493e,64a3d,c9fdd,21f14,53c76,ddd2d,7f5d0,f8543,ee954,533ba,dcd4a,2c15b,8ac1a,e97d7,10e03,0202c,b109d,ebf95,0f7f1,0bca9,36b59,9eefd,eb795,b2a2b,704ea,856e9,9e92c,e76a1,e3970,c36f5,5a407,ee9d9,aeb78,0a570,bdc91,f8f59,c08f0,bb45b,515d9,b347d,28b17,b3dab,bbbbd,94c53,54a92,f1e50,09587,c7890,7a9b3,354b9,e2803,78c8c,256e7,3a8cc,43137,883e8,4f318,b7641,f3192,5a496,1c1fa,7e43d,a50ed,87ad2,9ea88,c788b,95c60,ca436,007c7,a7057,cab0a,5afed,e32ce,7a961,157f8,fc304,12c14,179bc,82e35,863ac,bd2f8,5655d,62935,ff906,8eda8,bad13,8714d,af074,303f7,d4bf5,c78bc,97940,7a981,c87e2,bb685,eb46c,b14b5,7c563,7fc96,e5540,7134a,b85c7,49e6f,9d464,aba3d,60a01,e11cd,bc16b,8ff78,cd884,b2efe,79e6b,dd188,969c7,bc7d9,a856f,c8f91,bb731,45056,658d9,ba732,ebf44,5e748,33f22,58c97,4f211,94644,ee187,881a9,97ecd,6017d,c0b7e,1ad72,5c82d,8146e,3b63a,32c78,c5ac6,9a9ad,9c436,3ce2d,f7e51,b1371,28e07,e39fb,a74c9,2d870,73ccd,e5cfc,04f25,77e6e,9c259,59e10,9f83a,a8d5b,40245,6b3b1,473e8,a215a,b6313,2578c,27457,ca78c,140ef,dbab9,67aac,be529,9fa10,c158f,3e964,5d883,c996e,1e2bb,fc9c7,c096c,07512,683c0,ac2bf,981ea,54456,5f324,90575,db76b,817db,60ea8,8502e,b30e3,90414,a44b7,87ad5,d6e51,6112b,3f620,d23ee,c3f1f,5c057,aafad,63844,0b51d,51231,6679a,bc264,e1353,97cd8,50512,56ecd,610f0,205d7,ed246,c0b90,c9b5c,6d806,48695,961e8,dec7c,71b2c,6a3c6,02b1d,8635f,b8bc4,73790,0a39e,128be,b6b28,88e4f,542df,60ef6,321d8,9be31,48d07,c007a,aea99,837e2,16d82,b260a,21389,906cb,59cd0,d8d85,2da51,674bb,14ef3,71dca,0634a,893a8,0e0ec,e7ef9,15d22,80b13,436f7,6e7e9,60428,a04f4,efbe5,2e063,6aae7,614f2,a4e14,ab335,0e9e1,f1b88,a30a3,8e766,b2b36,b32a7,208cd,8d6c5,ca538,35b1c,c128c,88bc8,c123a,0ec98,83b56,6641b,b279a,242e0,a14a9,0bed0,9795a,d802e,ab41c,db4a1,e0842,05f62,44840,e79b5,91a1e,69132,bf47f,80796,3cf91,779b3,52c5e,44de9,dcd2f,ceee6,993c9,c4552,2b757,3a24b,0766b,4d6fa,d9703,bda35,3cb4e,eeef6,3cd13,9103a,8fcad,c6424,76bcc,6746e,8022f,ad831,5fef8,53998,abfa9,93c85,f2b94,a34ce,c831f,14088,81cff,c2719,23fe1,e0774,4d34d,e2912,c516b,8d197,8bc73,9269f,3cbdc,05320,e7e31,78e16,b61d6,a8bec,cce92,f68ba,a0252,d058b,f8dde,e1e40,b733e,b812d,aea74,e417f,beca3,f7c37,bff53,a0c66,c87c0,f0175,e996e,f1b8f,b20eb,c5b0f,e72f8,d57bf,fffcc,de5e6,ef8b1,b20f2,e3834,cb709,fc06f,a4af2,e376f,d79a1,acd5a,ba00b,d5399,f8091,c218a,d67d2,a740f,d324d,fa535,a1ffa,bcbed,e7755,cc3f0,aaef0,b6c1d,a3f35,ebed2,f8175,bebd6,cdf38,f8679,ccf4a,f1c28,bf561,b1477,babb5,ac9f8,f2f75,fbc74,c0f8d,c72e1,bc708,d9ac6,ea6fa,da81e,df72f,faa0e,addb6,c8ac1,a8a27,f3548,f634b,ec2cf,a4d17,e68d1,eff90,d51b1,bdfee,e0dc2,e421a,b8a92,e1b62,d01d0,cc671,c153a,fc9cf,df350,d2c22,df916,c5d21,f765e,aa2d4,a9d8d,c2b36,ca016,b4e29,ac2fa,e4599,b83cd,f586d,ef7bf,b0c07,fc6d2,eeec7,e720e,b558e,ef56f,b3353,a6de8,fab1d,c921e,b6a29,a0019,b03ef,cc742,a3d8d,b4e35,e6668,fe71a,fd836,cded9,c458e,d454b,b2f57,deda8,ab459,f47b9,f0356,d2f78,e6b0c,ac32f,f78d5,d1c4e,da652,b391c,a2fc6,a77f4,de655,f8baf,b66e9,c8b74,d1dfa,ee79c,c3612,ec3f1,ea5c6,d0a61,c08cf,d7f50,f2685,ab910,f173e,d1499,ebcdd,f762d,e97b3,a47eb,e32c8,db61e,c8dca,fcfdd,e0051,d40d5,cfec0,f7cf1,af433,e4017,bc343,d5ba9,d60fe,bb346,a1b8c,ab5ed,b65e5,ec1cf,a7798,e6737,ea3b8,e1076,ce973,a5c75,ce15f,d70aa,dbc04,dce8a,b5565,a68f0,abc90,c1792,eddfa,ab24c,ac20a,a732d,e49d4,e7fb1,fface,e48cf,fa808,cc8b2,fe112,bcf86,c0e70,e085b,bc95e,fc890,cf8b5,cac27,c4e9c,ce788,ca5c8,b554b,d68a4,db427,b20b7,be61d,b0fc3,b18a2,c7946,ea80b,abb99,b9529,ddd67,b9d3e,b8b96,fc5da,ec6c4,d5cea,e1a86,f55b7,b4a50,cf3cb,e270a,d15ab,f7603,b0b77,b3cfa,c73e0,519d9,6d9af,ff6ac,0e915,9ac33,d927d,b47e4,f63f1,4e160,c5f3b,616e0,6cd0d,89473,f4f21,9bcb3,2867b,807a8,130fb,12c69,017d6,6aeaa,fe06a,59fbd,4a0ff,d27ca,eb735,819ab,4f065,f4a64,a6615,95ff2,e5b71,2c989,8b864,67974,8109c,a376e,9e031,80cf3,e7b13,084fd,ff06b,2e73a,50e6b,238d6,6e76a,859eb,467bf,21e1a,961a7,bd190,86f9b,93a64,d72d6,b12b0,ca724,46d09,b8699,78c25,a7f66,ffcd7,7b165,04636,5841a,c1cc5,290e8,c97bc,88155,a4330,8619d,9bc46,dbb4a,81427,1fe18,69abd,4639e,31152,3a172,e6d89,65b42,08412,d087e,c6cc0,85d52,ba77a,0afcd,33a5e,b60ef,ca7d7,8e6ac,71375,61b21,eb252,0ad2c,2dd2f,5a7b7,c0fdf,cf98b,38e59,e8b7c,118f9,fd67f,2c3bb,d4024,c4a96,09f62,22173,f308d,df4cc,ce9b0,90577,397c5,fe055,19b64,efa09,10e0c,53c4b,14258,9bbfc,6bb19,0ed7e,38f11,4fa06,e5dd8,cf457,52ea4,38e5c,4193a,9b59f,26352,71e5e,d923d,c204e,7170f,d5470,c16c1,a5b36,51fe7,80b37,44ac6,37b37,1243e,d3937,3e01b,65c9d,3fea6,2a2c3,1cb7a,9821c,7971e,1163c,49c8f,646d7,54584,32bfa,b9ed8,8b4b7,7b211,4b622,69a0d,75b11,45352,44bf2,f7294,f1353,284e5,c00dd,57854,44d40,128d2,2205b,94278,e9c3b,6f533,b6b90,58638,4f718,0f36c,1ac30,34b2f,72e3c,2b14a,574e6,41689,66c69,79bf5,7e87f,8bb46,d1d95,b3c79,0b2b6,95c8c,321df,61c35,d4e94,16c87,e4408,8bd10,003c0,5a1d3,42799,edac5,005e8,cb158,f6bf8,547de,1840d,a2f3b,3d25a,965f0,5bd1b,cf0d7,40922,a579e,aa5be,d9a9d,bc86a,fd8c1,d84cc,e066a,a8c25,edd5e,36d33,2c773,fecd1,f52c9,e32ed,b3cc3,8aaae,1dccc,aa0f0,a73f1,7d027,68418,73131,8e24f,8a579,e6fb8,f1bbf,801c6,d4eb6,e79a0,85d3d,077c8,e001c,45cf4,8362b,c00e3,047f6,e5678,4d14b,c045d,1f4a4,a99b0,1e938,d3633,b84e8,f3c29,2fc4a,195c0,6000b,49b05,0203b,6effd,9a31a,3ba9a,eaa09,f0573,6d220,2fa6c,f9acd,c1cb6,43b6e,fa908,ba1cf,dd3c4,64fdd,d7ddf,e6f82,b4c0a,79d4f,df8c9,9c0a2,b121c,aa5c5,ac2b2,a5fa8,ee70b,56c48,23082,f6de7,d5275,e97d9,4ee52,c8971,c8eb5,927a3,33416,4507d,b5113,e7f9d,853ef,97b3c,3cfb2,fecd3,aa1d3,178e3,10b7d,c8c06,f33bb,e046d,0c159,abf33,0a7bd,a990d,1e31d,daf75,49268,f0e5e,6b4f8,bd4f8,684b6,b2701,9c972,69103,17d69,2ea7b,ce1c0,30081,02465,859de,6b269,307f5,d2870,8ffaf,222a3,183b4,a9bfb,d693a,bc73e,9b2eb,b7749,abf5d,abeaa,8de3b,a1a23,08fb6,52c84,23d21,2ae95,636ee,7cd61,98a4f,f12bb,f5aa6,2566e,b107b,b4fa8,3bff4,a174e,322cf,1eea3,f80c5,a0e5a,34b1f,afa49,29305,9585c,a236a,82381,d7a96,41172,2a1e0,6ce2a,2f303,49452,5f567,e7b8a,edddd,5ec6d,e8369,bea53,7b903,212b0,35f9b,0cc9a,24b24,5cfe9,b78ae,ce597,8bfb9,ac70b,da0b2,e4568,e6786,d5da8,abcda,d85eb,b0fd9,ed9a4,f0b48,bce0a,fdf29,fbefb,ab641,fb21f,d770c,ec608,d6e33,f73e8,c661f,efc46,ba9d4,f911c,ed8bc,ef63d,be67e,c9c90,cfa3e,2a692,88fbb,88658,c0bd1,568f4,2cca3,3cd85,91402,eca62,d4863,70705,d47f6,3b054,29a98,1e3c8,ccc22,fcaa3,43b54,5eaf6,5c85d,dfcfa,6497c,da3cc,bbd1c,62646,212f6,49141,b6396,6bfe9,14b90,47364,8798b,0eec5,83039,8b0b5,f43f7,b2dea,a8723,4e5bd,c741c,33380,43429,503c6,05fcb,70446,35d8c,4d9c9,25e1c,c5ad4,a2372,07ba3,53515,2ddaa,549c1,c92ea,39a17,ea5ef,f7ca4,e1817,86aea,ca38a,243cf,2a4ee,42e8d,09f91,3f35d,11e0b,072c6,73b62,d4333,5b9c6,0b507,f027c,5aea2,e78cd,602cd,c723b,54fa6,9d161,11fbd,fd2e1,6425d,fb2b7,0ea23,368fa,78d15,95162,19158,3bda1,e1861,8f8eb,5cfa8,786db,60697,2048c,c10b7,99425,7e170,44af8,0fa2e,783ba,83705,5c305,85b33,f9b21,4c0b1,f5ac0,5fddb,58158,8c539,252fe,871b9,24fc4,09f74,b9564,a7a67,d5212,657d8,9e71f,d5671,4f2f5,dde4a,d9948,5e4f0,0fce3,30b17,76889,c8367,330a4,2136b,9b3aa,da6f6,03acc,b8b49,9b26d,efb1c,0335b,e1ff8,84748,fc362,bb949,52b1f,d889e,7d679,278c4,1e33a,61585,0e2a8,04ad2,66e1d,35e89,c3f4e,24d88,63e36,a8539,8b54b,99028,4f644,681cc,d4b63,45a57,87437,310a7,26880,a631e,7a736,b2b3f,8af48,ddf01,a1e78,2dd02,90ae2,8ebd5,a922c,34e3a,96c58,1d849,ab04f,d9e12,fdec7,0b9d5,1cc77,6a6eb,76eac,e00c4,1f79d,2568c,060cb,c974f,77894,e3639,99176,08f47,7d3e8,5d5f9,fa17e,21ae2,445f8,4a294,c6cd0,db775,6e474,ecb0a,aa3c7,cf79b,30d3b,376b0,e28bd,0a9df,fc6d8,70456,d7f5e,74deb,bd184,01761,0ab46,9e209,c2780,fae95,efd55,5129f,d981e,b095f,d990a,dca62,de660,a0943,d303e,d3db8,dd9f2,a01c5,e7852,e71e3,f88b3,aed38,e4038,c05db,b4281,bddb4,b1ecf,f74af,e9fcc,d5370,f319a,a4931,b400e,adef2,d3047,eb6e6,a6c84,c769b,b574d,b1277,dbd4c,d8939,b475c,b926d,e4ecd,cf96a,b1460,43831,4be83,ab827,09298,de6ca,39c10,9b2b8,5ff22,48aeb,82f57,7ca7d,b4173,0b0a2,ae848,953e8,de7cc,86e55,109bf,a7f08,55208,1b0aa,db1e7,8ac2e,02a6c,33e3b,7d133,b1c42,fae58,039c3,26425,ecf67,5dd2c,cf4b7,3af32,a1ec0,37572,85680,c331c,27222,f11ad,c619f,ee425,5286a,9f093,d3dcf,80ac4,97e71,d29fa,73988,abce4,c1072,8b749,abb35,e3c04,3ebcf,27a67,1eca2,3ca38,f0d9a,08a0f,6efd4,535ff,b0cfa,2be29,2e6f9,5e5a0,0331c,8797d,42700,b2d3b,ee98d,28198,a2b02,ba561,2dd94,f935c,42380,b5ebc,9887c,9970d,5ce92,7606b,d2f61,4cdcc,e4e52,f9e1f,99047,57680,f08fb,e1603,ff658,1e293,d7b66,b1ed6,94ac8,92d2c,f5541,20a5b,48979,f0bdd,7c362,4fc99,154c4,dfaec,f9a9c,95fb6,b2414,a1a57,b0e99,a8ea1,c28af,d943c,d8e2c,b99f1,b94b8,fa1d8,c4fcc,f8c1b,cb560,a8fdf,b4364,d463e,e9545,f21fc,c720e,c8821,f9f0d,ab201,d9367,f9a18,f7ae4,b415c,dbcd8,a60ba,a195a,ede25,fb8b9,cdad5,f52b0,d000a,f02ff,f898e,b1cdc,b6340,e4fa1,bd39e,a3d71,c79c1,c4a20,ce523,fb29c,eec0c,3576d,41eed,aaba2,c0138,7fd3e,ee164,46c17,8302c,e6b90,fca49,97736,c3502,e35a4,585e2,eee72,ee94f,a2ba8,0a40d,47864,90832,ba75e,4e3a9,07d62,75b2c,76f65,eca2f,b389c,66a17,b01bf,c5098,d62fa,89687,94f69,6da2f,dc76e,6c125,6802e,a69a4,96eed,c12c3,d40fe,d8dee,e95ce,f8a38,dbd1f,f7681,d825b,c4903"ExamCodes = ExamCodes.split(',')file = docx.Document()headers ={'Connection': 'close'}for i in range(0, ExamCount):  ExamCodei=ExamCodes[i]  urlselecti = 'https://tkdata.mnks.cn/ExamData/'+ ExamCodei +'.JSON?CALL=?20201231143735.json' #选择题  responsei = requests.get(urlselecti, headers=headers,timeout=50,verify=False)  resulti = responsei.json()  ExamTi = resulti['tm'].split('<br/>')  if(len(ExamTi) > 1):    print(str(i+1)+'、'+ExamTi[0] + ' 答案:' + resulti['da'] + '\n  ' + ExamTi[1] + ' ' + ExamTi[2] + ' ' + ExamTi[3] + ' ' + ExamTi[4])    file.add_paragraph(str(i+1)+'、'+ExamTi[0] + ' 答案:' + resulti['da'])    if (resulti['tv'] != ''):      ExamTiimg = resulti['tv'].split('/')      ExamTiimgurl = 'Https://sucimg.itc.cn/sblog/' + ExamTiimg[2]      print(ExamTiimgurl)      download_img(ExamTiimgurl, ExamTiimg[2])      paragraph = file.add_paragraph() # 图片居中设置      paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER      run = paragraph.add_run("")      run.add_picture("D:\\Program Files (x86)\\PyCharm Community Edition 2020.1.1\\PaQukemu4tiku\\folder\\imgpath\\" + ExamTiimg[2] + '.gif')    file.add_paragraph('    '+ExamTi[1] + '   ' + ExamTi[2] + '   ' + ExamTi[3] + '   ' + ExamTi[4])  else:    print(str(i+1)+'、'+resulti['tm'] + ' 答案:' + resulti['da'])    file.add_paragraph(str(i+1)+'、'+resulti['tm'] + ' 答案:' + resulti['da'])    if (resulti['tv'] != ''):      ExamTiimg = resulti['tv'].split('/')      ExamTiimgurl = 'https://sucimg.itc.cn/sblog/' + ExamTiimg[2]      print(ExamTiimgurl)      download_img(ExamTiimgurl, ExamTiimg[2])      paragraph = file.add_paragraph() # 图片居中设置      paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER      run = paragraph.add_run("")      run.add_picture("D:\\Program Files (x86)\\PyCharm Community Edition 2020.1.1\\PaQukemu4tiku\\folder\\imgpath\\" + ExamTiimg[2] + '.gif')  #time.sleep(1)file.save("D:\\Program Files (x86)\\PyCharm Community Edition 2020.1.1\\PaQukemu4tiku\\folder\\C1科目四1487题.docx") #保存

4、运行结果

Python如何爬取科目四考试题库

        在项目文件夹下folder中imgpath保存所有题目的图片,C1科目四1487题.docx就是运行结果。
打开Word文档进行查看:

Python如何爬取科目四考试题库

Python如何爬取科目四考试题库

word文档可另存为pdf

Python如何爬取科目四考试题库

Python如何爬取科目四考试题库

        与科目一不同的是,科目四里很多选择题中的图片是动态的GIF图,而不是静态的png,所以题目保存到Word中后图片并不会动态显示,因此,考虑将Word文档另存为网页文件(.html

Python如何爬取科目四考试题库

结果(包含动画)如下图所示:

Python如何爬取科目四考试题库

Python如何爬取科目四考试题库

感谢各位的阅读!关于“Python如何爬取科目四考试题库”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

--结束END--

本文标题: Python如何爬取科目四考试题库

本文链接: https://lsjlt.com/news/269558.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • Python如何爬取科目四考试题库
    这篇文章给大家分享的是有关Python如何爬取科目四考试题库的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1、环境PyCharmPython 3.6pip安装的依赖包包括:requests 2.25.0、urll...
    99+
    2023-06-14
  • Python爬取科目四考试题库的方法实现
    1、环境 PyCharm Python 3.6 pip安装的依赖包包括:requests 2.25.0、urllib3 1.26.2、docx 0.2.4、python-do...
    99+
    2024-04-02
  • 利用python爬取软考试题之ip自动代理
    前言 最近有个软件专业等级考试,以下简称软考,为了更好的复习备考,我打算抓取www.rkpass.cn网上的软考试题。 首先讲述一下我爬取软考试题的故(keng)事(shi)。现在我已经能自动抓取某一个模块...
    99+
    2022-06-04
    试题 软考 python
  • Python如何爬取历年高考分数线
    本篇文章给大家分享的是有关Python如何爬取历年高考分数线,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。粉丝独白高考已经结束了,相信绝大部分同学都在放松自己了,毕竟压抑了这么...
    99+
    2023-06-17
  • 如何用python爬取知乎话题?
    因为要做观点,观点的屋子类似于知乎的话题,所以得想办法把他给爬下来,搞了半天最终还是妥妥的搞定了,代码是python写的,不懂得麻烦自学哈!懂得直接看代码,绝对可用 #coding:utf-8 """ @author:haoning @cr...
    99+
    2023-01-31
    如何用 话题 python
  • Python如何实现考试自动答题功能
    这篇文章主要介绍“Python如何实现考试自动答题功能”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Python如何实现考试自动答题功能”文章能帮助大家解决问题。一、准备环境1)运行环境 ...
    99+
    2023-07-05
  • 如何使用Python爬取历年高考数据并分析
    这篇文章给大家分享的是有关如何使用Python爬取历年高考数据并分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。开发工具**Python版本:**3.6.4相关模块:pyecharts模块;以及一些Python...
    99+
    2023-06-15
  • Python 面试中如何高效解决 leetcode 题目?
    在参加 Python 面试时,经常会遇到 leetcode 题目。如何高效地解决这些问题,成为了每个 Python 开发者必须掌握的技能。以下是一些有用的技巧和建议。 熟悉 Python 基础知识 在解决 leetcode 题目时,熟...
    99+
    2023-09-25
    面试 leetcode 重定向
  • Python 实时面试中如何高效解决 LeetCode 题目?
    LeetCode 是一个非常著名的算法题库,其中包含了很多经典的算法问题,这些问题往往是面试中常见的问题。而 Python 作为一门强大的编程语言,也有很多可以用来解决 LeetCode 问题的技巧和工具。 在实时面试中,时间非常有限,因...
    99+
    2023-09-06
    实时 面试 leetcode
  • Python爬虫如何获取数据并保存到数据库中
    本篇内容主要讲解“Python爬虫如何获取数据并保存到数据库中”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python爬虫如何获取数据并保存到数据库中”吧!1.简介介绍-网络爬虫(又称为网页蜘...
    99+
    2023-07-02
  • 如何使用Python爬虫实现抓取电影网站信息并入库
    这篇文章主要介绍如何使用Python爬虫实现抓取电影网站信息并入库,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!一.环境搭建1.下载安装包访问 Python官网下载地址:https://www.python.org/...
    99+
    2023-06-29
  • 在Python中使用requests库爬取数据时返回为空如何解决
    在Python中使用requests库爬取数据时返回为空如何解决?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Python主要用来做什么Python主要应用于:...
    99+
    2023-06-06
  • Python面试:如何在Shell中快速解决LeetCode难题,让面试官刮目相看?
    在准备Python面试时,LeetCode难题是必须要掌握的。而有些难题需要在Shell中快速解决,这既能提高我们的效率,又能让面试官刮目相看。本文将会介绍如何在Shell中快速解决LeetCode难题。 1.安装LeetCode-cli...
    99+
    2023-10-26
    面试 shell leetcode
  • 如何解决Python爬取网页时请求中收到响应400的问题
    这篇文章将为大家详细讲解有关如何解决Python爬取网页时请求中收到响应400的问题,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。一般情况下抓取网页时找到url中可以从 post 请求中获取数据,但得到的...
    99+
    2023-06-20
  • Python如何通过Scrapy框架实现爬取CSDN全站热榜标题热词
    小编给大家分享一下Python如何通过Scrapy框架实现爬取CSDN全站热榜标题热词,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!环境部署scrapy安装pip install scrapy ...
    99+
    2023-06-25
  • 如何使用python实现简单爬取网页数据并导入MySQL中的数据库
    前言:要使用 Python 爬取网页数据并将数据导入 MySQL 数据库,您需要使用 Requests 库进行网页抓取,使用 BeautifulSoup 库对抓取到的 HTML 进行解析,并使用 PyMySQL 库与 MySQL 进行交互。...
    99+
    2023-10-18
    python 数据库 爬虫
  • Python面试高频问题:如何使用HTTP库进行文件操作和网络请求?
    在Python开发中,HTTP库是非常重要的一个模块,它可以帮助我们实现网络请求和文件操作等功能。在面试中,面试官也会经常问到与HTTP库相关的问题。本文将针对HTTP库的使用进行详细介绍,并附上代码演示。 一、HTTP库简介 HTTP(...
    99+
    2023-09-21
    http 文件 面试
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作