注意:处理需要用户名密码认证的网站,需要auth字段。

# -*- coding:utf-8 -*-

import requests

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
}

newUrl ="https://www.freebuf.com/articles/system/187792.html"
#最简单的爬虫请求.也可以加上headers字段,防止部分网址的反爬虫机制
response = requests.get(newUrl)
#当爬取的界面需要用户名密码登录时候,构建的请求需要包含auth字段
#response = requests.get(newUrl,headers=headers,auth=('username','passsword'))
print(response.content.decode("utf-8"))#打印网页内容
#print(response.status_code)#浏览器返回的错误码,200表示成功

 

相关文章:

  • 2021-12-17
  • 2022-12-23
  • 2021-12-10
  • 2022-02-26
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-18
  • 2022-12-23
  • 2022-02-24
  • 2021-11-28
  • 2021-03-28
  • 2021-10-28
  • 2021-05-05
相关资源
相似解决方案