置顶 老师参与

Requests库的爬取性能分析

嵩天 发表于2023年10月16日
<p>尽管Requests库功能很友好、开发简单(其实除了import外只需一行主要代码),但其性能与专业爬虫相比还是有一定差距的。请编写一个小程序,“任意”找个url,测试一下成功爬取100次网页的时间。(某些网站对于连续爬取页面将采取屏蔽IP的策略,所以,要避开这类网站。)</p><p>请回复代码,并给出url及在自己机器上的运行时间。</p><p><br/></p><p><br/></p><p><br/></p>
82 回复

    1楼

  • k12161118465085660328 发表于2023年10月18日
    0 | 0 | 举报
    <p>import requests</p><p>import time</p><p><br ></p><p>def web_request(url, num):</p><p>&nbsp; &nbsp; start_time = time.perf_counter()&nbsp; &nbsp; # 循环开始时间</p><p>&nbsp; &nbsp; for i in range(1, num):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; try:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = requests.get(url)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.raise_for_status()&nbsp; &nbsp; # 若返回的状态码不是200,将产生一次异常</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.encoding = r.apparent_encoding&nbsp; &nbsp; # 从内容分析出的响应内容编码方式(备选编码方式)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; except:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;Error&quot;)</p><p>&nbsp; &nbsp; end_time = time.perf_counter()&nbsp; &nbsp; &nbsp; # 循环结束时间</p><p>&nbsp; &nbsp; times = end_time - start_time</p><p>&nbsp; &nbsp; print(&quot;访问链接:%s,%s次用时%s秒&quot; % (url, num, times))</p><p><br ></p><p>web_request(&quot;https://www.python123.io/&quot;, 100)</p><p>结果:</p><p>访问链接:https://www.python123.io/,100次用时45.44711459999962秒</p><p><br ></p>
    k12161118465085660328 发表于2023年10月18日
    添加评论
  • 2楼

  • 包盛炜 发表于2023年10月20日
    0 | 0 | 举报
    <p>import requests</p><p>import time</p><p>def web_request(url,num)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;star_time=time.perf_counter()<br ></p><p>for i in range(1,num):</p><p>&nbsp;&nbsp;&nbsp;&nbsp;try:<br ></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r=requests.get(url)<br ></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.raise_for_status()<br ></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.encoding=r.apparent_encoding<br ></p><p>&nbsp;&nbsp;&nbsp;&nbsp;except:<br ></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;发生错误&quot;)</p><p>end_time=tim.perf_counter()</p><p>times=end_time-start_time</p><p>print(&quot;访问链接: {},{}次用时{}秒”format(url,num,times))</p>
    包盛炜 发表于2023年10月20日
    添加评论
  • 3楼

  • mooc125797629048713026 发表于2023年10月22日
    0 | 0 | 举报
    <p>&gt;&gt;&gt; import requests</p><p>&gt;&gt;&gt; def getHTMLText(url)</p><p>SyntaxError: invalid syntax</p><p>&gt;&gt;&gt; try:</p><p> r = requests.get(url,timeout=30)</p><p> r.raise_for_status()</p><p> r,encoding = r.apparent_encoding</p><p> return r,text</p><p>except:</p><p> return &quot;产生异常&quot;</p><p>SyntaxError: 'return' outside function</p><p>&gt;&gt;&gt; if _name_ == &quot;_main_&quot;:</p><p> url = &quot;https://www.baidu.com&quot;</p><p> end_time = time.perf_counter()</p><p> times = end_time - start_time</p><p> print(getHTMLText(url))</p><p><br ></p><p> </p><p>Traceback (most recent call last):</p><p>&nbsp; File &quot;&lt;pyshell#14&gt;&quot;, line 1, in &lt;module&gt;</p><p>&nbsp; &nbsp; if _name_ == &quot;_main_&quot;:</p><p>NameError: name '_name_' is not defined</p><p>&gt;&gt;&gt;&nbsp;</p><p><br ></p>
    mooc125797629048713026 发表于2023年10月22日
    添加评论
  • 4楼

  • 边境的海🌊 发表于2023年10月24日
    0 | 0 | 举报
    <img src="https://mooc-image.nosdn.127.net/5836BE094B4297CD7C880F890FAD9C70.jpg" style="max-width : 100% ;" >
    边境的海🌊 发表于2023年10月24日
    添加评论
  • 5楼

  • Mr_Doctor 发表于2023年10月26日
    4 | 0 | 举报
    <p>import requests<br >import time<br >def gethtmltext(url):<br > &nbsp; &nbsp;try:<br > &nbsp; &nbsp; &nbsp; &nbsp;r = requests.get(url,timeout=30)<br > &nbsp; &nbsp; &nbsp; &nbsp;r.raise_for_status()<br > &nbsp; &nbsp; &nbsp; &nbsp;r.encoding = r.apparent_encoding<br > &nbsp; &nbsp; &nbsp; &nbsp;return r.text<br > &nbsp; &nbsp;except:<br > &nbsp; &nbsp; &nbsp; &nbsp;print('异常')<br >num = int(input('请输入爬取次数:'))<br >start_time = time.perf_counter()<br >for i in range(num):<br > &nbsp; &nbsp;if __name__ == '__main__':<br > &nbsp; &nbsp; &nbsp; &nbsp;url = 'https://www.baidu.com'<br > &nbsp; &nbsp; &nbsp; &nbsp;print(gethtmltext(url))<br >end_time = time.perf_counter()<br >times = end_time - start_time<br >print('访问链接%s,%s次,用时%s秒'%(url,num,times))</p><p>访问链接<a href="https://www.baidu.com,100次,用时6.774300699995365秒" >https://www.baidu.com,100次,用时6.774300699995365秒</a> </p><p><br ></p>
    Mr_Doctor 发表于2023年10月26日
    添加评论
  • 6楼

  • 210420210082吴若昀 发表于2023年10月27日
    0 | 0 | 举报
    <p>import requests</p><p>import time</p><p>def gethtmltext(url):</p><p>&nbsp; &nbsp; try:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r=requests.get(url,timeout=30)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.raise_for_status()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.encoding=r.apparent_encoding</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return r.text</p><p>&nbsp; &nbsp; except:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return&quot;产生异常&quot;</p><p>num=int(input(&quot;请输入爬取次数:&quot;))</p><p>start_time=time.perf_counter()</p><p>for i in range(num):</p><p>&nbsp; &nbsp; if __name__=='__main__':</p><p>&nbsp; &nbsp; &nbsp; &nbsp; url=&quot;https://www.baidu.com&quot;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; print(gethtmltext(url))</p><p>end_time=time.perf_counter()</p><p>times=end_time-start_time</p><p>print(times)</p><p><br ></p><p>访问htttp://www.baidu.com,用时304.4556889999658s</p>
    210420210082吴若昀 发表于2023年10月27日
    添加评论
  • 7楼

  • 爱吃派k12337485756138147 发表于2023年10月29日
    0 | 0 | 举报
    <p>import time</p><p>import requests</p><p>def getHTMLText(url):<br > &nbsp; &nbsp;try:<br > &nbsp; &nbsp; &nbsp; &nbsp;r=requests.get(url,timeout=30)<br > &nbsp; &nbsp; &nbsp; &nbsp;r.raise_for_status()<br > &nbsp; &nbsp; &nbsp; &nbsp;r.encoding=r.apparent_encoding<br > &nbsp; &nbsp; &nbsp; &nbsp;return r.text<br > &nbsp; &nbsp;except:<br > &nbsp; &nbsp; &nbsp; &nbsp;return &quot;产生异常&quot;<br >s=[]<br >if __name__ == '__main__':<br > &nbsp; &nbsp;url=&quot;https://www.baidu.com&quot;<br > &nbsp; &nbsp;for i in range(100):#爬取100次百度<br > &nbsp; &nbsp; &nbsp; &nbsp;start=time.time()<br > &nbsp; &nbsp; &nbsp; &nbsp;s.append(int(start))</p><p>&nbsp; &nbsp; &nbsp; &nbsp;getHTMLText(url)<br > &nbsp; &nbsp;end=time.time()<br > &nbsp; &nbsp;s.append(int(end))<br > &nbsp; &nbsp;print(max(s)-min(s))<br ><br ></p>
    爱吃派k12337485756138147 发表于2023年10月29日
    添加评论
  • 8楼

  • mooc15411646807685138 发表于2023年10月31日
    0 | 0 | 举报
    <img src="https://mooc-image.nosdn.127.net/B17AC8D11E16CC5EB35C24705F3B1FD4.jpg" style="max-width : 100% ;" >
    mooc15411646807685138 发表于2023年10月31日
    添加评论
  • 9楼

  • CCk12163137592035242276 发表于2023年10月31日
    0 | 0 | 举报
    <p>import time</p><p>import requests</p><p>def getHTMLTex(url):</p><p>&nbsp; &nbsp; try:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r=requests.get(url,timeout=30)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.raise_for_status()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.encoding=r.apparent_encoding</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return r.text</p><p>&nbsp; &nbsp; except:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return&quot;产生异常&quot;</p><p>&nbsp; &nbsp; s=[]</p><p>&nbsp; &nbsp; if_name_=='_main_'</p><p>&nbsp; &nbsp; url=&quot;https://www.baidu.com&quot;</p><p>&nbsp; &nbsp; for i in range(100):#爬取100次百度</p><p>&nbsp; &nbsp; &nbsp; &nbsp; start=time.time()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; s.append(int(start))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; getHTMLText(url)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; end=time.time()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; s.append(int(end))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; print(max(s)-min(s))</p><p><br ></p>
    CCk12163137592035242276 发表于2023年10月31日
    添加评论
  • 10楼

  • 0279苏春燕 发表于2023年11月01日
    0 | 1 | 举报
    <p>import requests</p><p>import time</p><p><br ></p><p>url=&quot;https://hao.360.com/?a1004&quot;</p><p>start_time=time.perf_counter()</p><p>for i in range(100):</p><p>&nbsp; &nbsp; try:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r=requests.get(url,timeout=30)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.raise_for_status()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.encoding=r.apparent_encoding</p><p>&nbsp; &nbsp; &nbsp; &nbsp; s=r.text</p><p>&nbsp; &nbsp; except:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; s=&nbsp; &quot;产生异常&quot;</p><p>end_time=time.perf_counter()&nbsp; &nbsp;</p><p>times=end_time-start_time</p><p>print(url)</p><p>print(times)&nbsp; &nbsp; &nbsp; &nbsp;</p><p><code class="brush:python;toolbar:false" >运行结果&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;91.20875530000012</code></p>
    0279苏春燕 发表于2023年11月01日
    添加评论
  • 11楼

  • Sherry_Shen_FISH 发表于2023年11月02日
    0 | 0 | 举报
    <p>import requests</p><p>import time</p><p><br ></p><p>def getHtml(url):</p><p>&nbsp; &nbsp; try:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r = requests.get(url, timeout = 30)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.raise_for_status()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.encoding = r.apparent_encoding</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return r.text</p><p>&nbsp; &nbsp; except:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return &quot;Exception&quot;</p><p>&nbsp; &nbsp;</p><p>if __name__ == '__main__':</p><p>&nbsp; &nbsp; url = 'https://www.baidu.com'</p><p>&nbsp; &nbsp; start = time.time()</p><p>&nbsp; &nbsp; for i in range(100):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; getHtml(url)</p><p>&nbsp; &nbsp; end = time.time()</p><p>&nbsp; &nbsp; print(end-start)</p><p><br ></p><p>时间:5.57</p>
    Sherry_Shen_FISH 发表于2023年11月02日
    添加评论
  • 12楼

  • 学员ae5akada26958167691472277 发表于2023年11月03日
    0 | 1 | 举报
    <p><code class="brush:python;toolbar:false" >import&nbsp;requests import&nbsp;time def&nbsp;getHTMLText(url): &nbsp;&nbsp;&nbsp;&nbsp;try: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res&nbsp;=&nbsp;requests.get(url) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res.raise_for_status() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res.encoding&nbsp;=&nbsp;res.apparent_encoding &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;res.text &nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;requests.HTTPError&nbsp;as&nbsp;ex: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(ex) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;'产生异常' &nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;requests.ConnectionError&nbsp;as&nbsp;ex: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(ex) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;'连接异常' if&nbsp;__name__&nbsp;==&nbsp;'__main__': &nbsp;&nbsp;&nbsp;&nbsp;url&nbsp;=&nbsp;'https://www.baidu.com' &nbsp;&nbsp;&nbsp;&nbsp;start&nbsp;=&nbsp;time.time() &nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i&nbsp;in&nbsp;range(100): &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getHTMLText(url) &nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;=&nbsp;time.time() &nbsp;&nbsp;&nbsp;&nbsp;print(end&nbsp;-&nbsp;start) 时间:7.1s</code></p>
    学员ae5akada26958167691472277 发表于2023年11月03日
    添加评论
  • 13楼

  • CUIT2021131124邢莎莎 发表于2023年11月03日
    0 | 0 | 举报
    <p>import requests<br >import time<br ><br ># 指定要爬取的URL<br >url = 'https://www.baidu.com'&nbsp; # 请替换为实际的目标URL<br ><br ># 定义爬取次数<br >num_requests = 100<br ><br ># 开始计时<br >start_time = time.time()<br ><br ># 循环爬取指定次数<br >for i in range(num_requests):<br >&nbsp;&nbsp;&nbsp; response = requests.get(url)<br >&nbsp;&nbsp;&nbsp; if response.status_code == 200:<br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(f'Successfully fetched data for request {i + 1}')<br >&nbsp;&nbsp;&nbsp; else:<br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(f'Failed to fetch data for request {i + 1}')<br ><br ># 结束计时<br >end_time = time.time()<br >execution_time = end_time - start_time<br ><br >print(f'Total time for {num_requests} requests: {execution_time} seconds')<br ><br ><br ></p><div id="simple-translate" class="simple-translate-system-theme" ><div><div style=" height: 22px; width: 22px; top: 113px; left: 154px;" class="simple-translate-button isShow" ></div><div class="simple-translate-panel " style="width: 300px; height: 200px; top: 0px; left: 0px; font-size: 13px;" ><div class="simple-translate-result-wrapper" style="overflow: hidden;" ><div class="simple-translate-move" draggable="true" ></div><div class="simple-translate-result-contents" ><p class="simple-translate-result" dir="auto" ></p><p class="simple-translate-candidate" dir="auto" ></p></div></div></div></div></div>
    CUIT2021131124邢莎莎 发表于2023年11月03日
    添加评论
  • 14楼

  • 开发_5G 发表于2023年11月04日
    0 | 0 | 举报
    为啥我访问要18秒
    开发_5G 发表于2023年11月04日
    添加评论
  • 15楼

  • 天野阳菜森岛帆高 发表于2023年11月05日
    0 | 0 | 举报
    <p>import requests<br >import time<br >def get_html_information(url):<br > &nbsp; &nbsp;try:<br > &nbsp; &nbsp; &nbsp; &nbsp;r=requests.get(url)<br > &nbsp; &nbsp; &nbsp; &nbsp;r.raise_for_status()<br > &nbsp; &nbsp; &nbsp; &nbsp;r.encoding=r.apparent_encoding<br > &nbsp; &nbsp; &nbsp; &nbsp;return r.text<br > &nbsp; &nbsp;except:<br > &nbsp; &nbsp; &nbsp; &nbsp;return &quot;数据异常&quot;<br >url=&quot;https://www.baidu.com&quot;<br >start=time.time()<br >for i in range(100):<br > &nbsp; &nbsp;get_html_information(url)<br >end=time.time()<br >print(f&quot;爬取百度网站100次用时{end-start}秒&quot;)</p>
    天野阳菜森岛帆高 发表于2023年11月05日
    添加评论
  • 16楼

  • CUIT2020131116区块链203周世磊 发表于2023年11月06日
    0 | 0 | 举报
    import requests import time def web_request(url,num) star_time=time.perf_counter() for i in range(1,num): try: r=requests.get(url) r.raise_for_status() r.encoding=r.apparent_encoding except: print(&quot;发生错误&quot;) end_time=tim.perf_counter() times=end_time-start_time print(&quot;访问链接: {},{}次用时{}秒”format(url,num,times))
    CUIT2020131116区块链203周世磊 发表于2023年11月06日
    添加评论
  • 17楼

  • bit1120221789周沛智 发表于2023年11月06日
    1 | 0 | 举报
    <p>import requests<br >import time<br >def get_html_information(url):<br > &nbsp; &nbsp;try:<br > &nbsp; &nbsp; &nbsp; &nbsp;r=requests.get(url)<br > &nbsp; &nbsp; &nbsp; &nbsp;r.raise_for_status()<br > &nbsp; &nbsp; &nbsp; &nbsp;r.encoding=r.apparent_encoding<br > &nbsp; &nbsp; &nbsp; &nbsp;return r.text<br > &nbsp; &nbsp;except:<br > &nbsp; &nbsp; &nbsp; &nbsp;return &quot;数据异常&quot;<br >url=&quot;https://www.baidu.com&quot;<br >start=time.time()<br >for i in range(100):<br > &nbsp; &nbsp;get_html_information(url)<br >end=time.time()<br >print(f&quot;爬取百度网站100次用时{end-start}秒&quot;)</p>
    bit1120221789周沛智 发表于2023年11月06日
    添加评论
  • 18楼

  • 21教技陆苑莹 发表于2023年11月08日
    0 | 0 | 举报
    <p>import requests</p><p>import time</p><p>def get_html_information(url):</p><p>&nbsp; &nbsp; try:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r=requests.get(url)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.raise_for_status()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r.encoding=r.apparent_encoding</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return r.text</p><p>&nbsp; &nbsp; except:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return &quot;数据异常&quot;</p><p>url=&quot;https://www.baidu.com&quot;</p><p>start=time.time()</p><p>for i in range(100):</p><p>&nbsp; &nbsp; get_html_information(url)</p><p>end=time.time()</p><p>print(f&quot;爬取百度网站100次用时{end-start}秒&quot;)</p><p><br ></p><p>bit112022178...11月6日</p><p><br ></p>
    21教技陆苑莹 发表于2023年11月08日
    添加评论
  • 19楼

  • 尹钰婷mooc111476321573068222 发表于2023年11月08日
    0 | 0 | 举报
    <p>import&nbsp;requests<br ><br >import&nbsp;time<br ><br >def&nbsp;web_request(url,num)<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;star_time=time.perf_counter()<br ><br >for&nbsp;i&nbsp;in&nbsp;range(1,num):<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;try:<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r=requests.get(url)<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.raise_for_status()<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.encoding=r.apparent_encoding<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;except:<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;发生错误&quot;)<br ><br >end_time=tim.perf_counter()<br ><br >times=end_time-start_time<br ><br >print(&quot;访问链接:&nbsp;{},{}次用时{}秒”format(url,num,times))<br >CUIT20201311...11月6日</p><p><br ></p>
    尹钰婷mooc111476321573068222 发表于2023年11月08日
    添加评论
  • 20楼

  • 韦国翔_ 发表于2023年11月08日
    0 | 0 | 举报
    <p>import&nbsp;requests<br ><br >import&nbsp;time<br ><br >def&nbsp;web_request(url,num)<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;star_time=time.perf_counter()<br ><br >for&nbsp;i&nbsp;in&nbsp;range(1,num):<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;try:<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r=requests.get(url)<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.raise_for_status()<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.encoding=r.apparent_encoding<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;except:<br ><br >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;发生错误&quot;)<br ><br >end_time=tim.perf_counter()<br ><br >times=end_time-start_time<br ><br >print(&quot;访问链接:&nbsp;{},{}次用时{}秒”format(url,num,times))</p>
    韦国翔_ 发表于2023年11月08日
    添加评论
点击加载更多