我对python中requests函数的理解

说到写爬虫程序,很多语言都可以写。其中python对新手特别友好,因为门槛低,自带的函数好用。所以现在很多人都开始自学python了

众所周知,爬虫分为4大步骤

   - 指定url  url = "网址"   
   - 发起请求  requests.get()
   - 获取响应数据              
   - 持久化存储     

以前可能调用的是urllib,自从有了requests之后,便取代了前者的地位。requests的作用是模拟浏览器发出请求,发出请求是爬虫的第一步,有了requests之后,便可用简单的代码就能实现发出请求的功能,如下:

import requests  #首先调用requests
url = “想要爬去的网址”
a = requests.get(url = url)

requests.get会返回一个响应对象,有了对象之后需要的是把他保存下来,所以接下来的代码就是把它保存起来

text = a.text
print(text)
with open(./'保存的名字.text‘,'w',encoding='utf-8') as fp:
   fp.write(text)

with open 括号里面的./表示的是保存到当前根目录下。第一个’‘里面写入的是文件名字和后缀,第二个’‘里面的是类型,第三个’‘里面的是字符编码,最后输出出来。

完整版代码如下:

没想到爬我自己的网站一下就成功了, 从而我也知道了我的网站是有多么脆弱,要是被谁攻击的话肯定立马就崩溃了,,不过这个辣鸡网站也没人会没事做攻击着玩叭(😁笑

最后附一张网站的截图

比起刚接触python的时候我个人感觉还是有进步的,循序渐进慢慢来就好,之前看的教程一下变难了就换了一个up主的教学视频从头学,个人推荐有了一点点基础后再看这个up主的。

23 COMMENTS
  1. 2021/08/03
    Hfunyl

    generic tadalafil no prescription - cialis generic usa discount tadalafil 20mg

  2. 2021/08/04
    Ppndxu

    online generic viagra prescription - sildenafil 130mg over the counter sildenafil prescription discount

  3. 2021/08/12
    Kbdvbd

    prednisone nz - prednisone prescription online prednisone 5mg coupon

  4. 2021/08/14
    Enwovy

    cheap real viagra - viagra 2010 how to buy viagra online safely in india

  5. 2021/08/15
    Bokkwd

    best tadalafil tablets - Buy cialis in usa chewable cialis

  6. 2021/08/17
    Cisqgq

    ivermectin buy nz - stromectol for sale online ivermectin 3mg dose

  7. 2021/08/19
    Wejmdh

    latest treatment for erectile dysfunction - ed medication online best ed pill

  8. 2021/08/22
    Iwkauw

    buy albuterol online - ventolin cost canada ventolin online

  9. 2021/08/24
    Mgvjpy

    cytotec where to buy - cytotec cvs where to buy cytotec over the counter in singapore

  10. 2021/08/25
    Mnybdm

    buy doxycycline online without prescription - doxycycline in mexico doxycycline 20 mg price

  11. 2021/08/27
    Xiottf

    order neurontin over the counter - levothyroxine 0.025 mg 450 mg synthroid

  12. 2021/08/28
    Stromectol

    Levitra Mecanismo De Accion

  13. 2021/08/28
    Gvwnpu

    viagra uk otc - purchase viagra safely online online pharmacy viagra usa

  14. 2021/08/28
  15. 2021/08/28
    web hosting a

    Howdy would you mind sharing which blog platform you're working with?
    I'm looking to start my own blog in the near future but I'm having
    a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your design and style seems different then most blogs and I'm looking
    for something unique. P.S Apologies for being off-topic but I had
    to ask!

  16. 2021/08/30
    Omadjd

    canadianpharmacyworld - where to buy cialis over the counter uk tadalafil india brand

  17. 2021/08/30
    t.co

    Your method of describing everything in this paragraph is in fact good, all be able to without
    difficulty understand it, Thanks a lot.

  18. 2021/08/30
    replicamagic

    a recommend web sites

  19. 2021/08/31
    Mctepq

    generic vardenafil online pharmacy - vardenafil pills online how to take vardenafil

  20. 2021/09/01
    http://t.co/

    I blog quite often and I truly appreciate your information.
    This article has truly peaked my interest. I'm going to book
    mark your blog and keep checking for new details about once a week.
    I opted in for your RSS feed too.

  21. 2021/09/01
    Viagra

    Kamagra Risks

  22. 2021/09/01
    Uogxli

    stromectol oral - stromectol for head lice ivermectin 1%cream

  23. 2021/09/01
    http://bitly.com

    If you are going for best contents like me, just visit this web page every day as it offers quality contents, thanks

loading