thread_num = 0 info = '访问成功' lock = threading.Lock() if urls == None: return None find_url_all_num = len(urls) content_url = "" content_subdomain = "" if self.args.verify !=0: print("A total of Find " + str(len(urls)) + " URL:\n") print("-----------------------But further validation is needed-----------------!\n\n\n") domian_text = requests.get(domian,verify =False).text print("The length of the page currently visited =>"+str(len(domian_text))) result ={} for url in urls: thread_num += 1 self.therads_op(url, content_url, lock,thread_num,result) if thread_num == 100: time.sleep(1) find_url_success_num = 0 for length,url_list in result.items(): print("-----------------------The return packet length is :{len}------------------------".format(len =length)) for url in url_list: print(url+"\n") find_url_success_num += 1 content_url+=url+"\n"
关键的一些代码,这里因为使用了网络验证,所以写了个多线程:
Code
1 2 3 4 5
def therads_op(self,url,content_url,lock,thread_num,result): threading.Thread(target=self.request(url,content_url,lock,result),args=(url,content_url,lock,result,)) if lock.acquire(): thread_num -= 1 lock.release()