简体   繁体   English

python 循环 subprocess.check_output

[英]python loop over subprocess.check_output

I want to do some data research about student's result in their final examination on http://diemthi.hcm.edu.vn/ enter image description here In this page you need to insert your "SoBaoDanh" to search your point at you final test我想对学生在http://diemthi.hcm.edu.vn/上的期末考试中的成绩进行一些数据研究 在此处输入图片描述在此页面中,您需要插入“SoBaoDanh”以在期末考试中搜索您的观点

For example enter image description here enter image description here "SoBaoDanh" start form 02000001 to 02089275 So how I can get hole of that result My code I wrote like this例如在此处输入图像描述在此处输入图像描述“SoBaoDanh”开始形式 02000001 到 02089275 那么我如何才能获得该结果的漏洞 我的代码是这样写的

import subprocess    
i = 2000001
    while i < 2089275:  
        result = subprocess.check_output([print("'curl - F" + '"SoBaoDanh=0'+ str(i+1) +'"' + "diemthi.hcm.edu.vn/Home/Show'")])
        print(result)
    i +=1

Instead of calling curl using subprocess , use the requests library to make http requests like so不要使用subprocess调用curl ,而是使用requests库来发出这样的 http 请求

import requests as r
for i in range(2000001, 2089275):
   res = r.post("http://diemthi.hcm.edu.vn/Home/Show", data={"SoBaoDanh": "0"+str(i)}) 
   print(res.content)

Since the result is an HTML document, you could use an HTML parser like bs4 to further filter the result stored in res.content to get only the part that you need.由于结果是一个 HTML 文档,您可以使用像bs4这样的 HTML 解析器进一步过滤存储在res.content的结果,以仅获取您需要的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM