zoukankan      html  css  js  c++  java
  • python的requests模块爬取网页内容

    注意:处理需要用户名密码认证的网站,需要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表示成功
  • 相关阅读:
    Python IDLE快捷键一览
    面试题——中
    面试题——君
    面试题——太(下)
    面试题——2面常见问题
    MYSQL数据库设计规范与原则
    字符串操作
    集合
    java-数组
    java异常处理机制
  • 原文地址:https://www.cnblogs.com/taoyuanming/p/10768495.html
Copyright © 2011-2022 走看看