主頁 > 知識庫 > Python爬取科目四考試題庫的方法實(shí)現(xiàn)

Python爬取科目四考試題庫的方法實(shí)現(xiàn)

熱門標(biāo)簽:工廠智能電話機(jī)器人 在哪里辦理400電話號碼 西藏智能外呼系統(tǒng)五星服務(wù) 平頂山外呼系統(tǒng)免費(fèi) 400電話申請服務(wù)商選什么 原裝電話機(jī)器人 江蘇客服外呼系統(tǒng)廠家 清遠(yuǎn)360地圖標(biāo)注方法 千陽自動外呼系統(tǒng)

1、環(huán)境


PyCharm

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

谷歌瀏覽器

2、目標(biāo)網(wǎng)站及請求分析

駕駛員考試網(wǎng)站


        從上圖中,可以看到科目四共有1487道題目,為了將所有的題目匯總到一個Word文檔中,需要獲取到每道題的文本和圖片。
        首先,打開谷歌瀏覽器訪問上述網(wǎng)站,鍵盤按F12,點(diǎn)擊Network,點(diǎn)擊左側(cè)題目中的向右箭頭,一直點(diǎn)擊下一道題,不斷發(fā)起請求,在右側(cè)可以看到每個題目的請求鏈接中只有五位字符的考試碼不一樣,所以我們要想辦法獲取每道題目的考試碼。


點(diǎn)擊其中的一個請求,在Headers中可以看到題目請求的url網(wǎng)址和狀態(tài),在Preview中可以看到題目的相關(guān)信息。


        然后用谷歌瀏覽器打開上述網(wǎng)站,然后鍵盤按F12,點(diǎn)擊sources,點(diǎn)擊左側(cè)Page下tk.mnks.cn下的lianxitix下的文件夾,可以看到Exam的相關(guān)變量信息,其中ExamCodes就是1487道題所對應(yīng)的考試碼。

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 requests
import time
import urllib.request
import docx
#創(chuàng)建內(nèi)存中的word文檔對象
from docx.shared import Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT

def 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()) # 將內(nèi)容寫入圖片
      return filename
  except:
    return "failed"

ExamVersion = "20210205090935"
ExamCount = 1487
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"
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() # 圖片居中設(shè)置
      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() # 圖片居中設(shè)置
      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、運(yùn)行結(jié)果


        在項(xiàng)目文件夾下folder中imgpath保存所有題目的圖片,C1科目四1487題.docx就是運(yùn)行結(jié)果。
打開Word文檔進(jìn)行查看:



word文檔可另存為pdf


        與科目一不同的是,科目四里很多選擇題中的圖片是動態(tài)的GIF圖,而不是靜態(tài)的png,所以題目保存到Word中后圖片并不會動態(tài)顯示,因此,考慮將Word文檔另存為網(wǎng)頁文件(.html)


結(jié)果(包含動畫)如下圖所示:


到此這篇關(guān)于Python爬取科目四考試題庫的方法實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Python爬取考試題庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • python爬取晉江文學(xué)城小說評論(情緒分析)
  • Python爬蟲之爬取2020女團(tuán)選秀數(shù)據(jù)
  • python爬取各省降水量及可視化詳解
  • python爬蟲之教你如何爬取地理數(shù)據(jù)
  • Python爬蟲之教你利用Scrapy爬取圖片
  • python基于scrapy爬取京東筆記本電腦數(shù)據(jù)并進(jìn)行簡單處理和分析
  • 用python爬蟲爬取CSDN博主信息
  • 利用Python網(wǎng)絡(luò)爬蟲爬取各大音樂評論的代碼
  • 詳解用python實(shí)現(xiàn)爬取CSDN熱門評論URL并存入redis
  • python 爬取壁紙網(wǎng)站的示例
  • Python爬蟲爬取全球疫情數(shù)據(jù)并存儲到mysql數(shù)據(jù)庫的步驟
  • Python爬蟲之爬取某文庫文檔數(shù)據(jù)

標(biāo)簽:西安 隨州 錦州 日照 股票 安慶 天水 白城

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python爬取科目四考試題庫的方法實(shí)現(xiàn)》,本文關(guān)鍵詞  Python,爬取,科目,四,考試題庫,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Python爬取科目四考試題庫的方法實(shí)現(xiàn)》相關(guān)的同類信息!
  • 本頁收集關(guān)于Python爬取科目四考試題庫的方法實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章