美文网首页
Python爬虫学习(一)

Python爬虫学习(一)

作者: rrrwx | 来源:发表于2019-06-12 12:33 被阅读0次

http://www.icourse163.org/course/BIT-1001870001?tid=1001962001#/info 授课老师:嵩天 课程简介:“The website is the API.”网络爬虫逐渐成为自动获取网络信息的主要形式。

Requests库的使用:


import requests

r = requests.get(url)

构造一个向服务器请求资源的Request对象(大写)
返回一个包含服务器资源的Response对象

(1)Response对象的属性

r.status_code(200表示连接成功)
r.text(url响应内容)
r.content(响应内容的二进制形式)
r.encoding(从头部预测的编码方式)
r.apparent_encoding(从内容分析的编码方式)
-------r.encoding = r.apparent_encoding

(2)通用框架


import requests

def getHTMLText(url):

    try:

        r = requests.get(url, timeout=30)

        r.raise_for_status()

        r.encoding = r.apparent_encoding

        return r.text

    except:

        return "wrong connection..."

if __name__ == "__main__":

    this_url = "http://www.baidu.com"

    print(getHTMLText(this_url))

(3)Requests库的主要方法


requests.request()---------基础方法

requests.get(); requests.head(); requests.post(); requests.put(); requests.patch(); requests.delete()

相关文章

  • Python爬虫学习(十六)初窥Scrapy

    Python爬虫学习(一)概述Python爬虫学习(二)urllib基础使用Python爬虫学习(三)urllib...

  • 资料

    Python爬虫系列(一)初期学习爬虫的拾遗与总结(11.4更) Python爬虫学习系列教程 Python爬虫学习手册

  • Python爬虫学习系列教程

    转自: 静觅»Python爬虫学习系列教程 Python爬虫学习系列教程 Python版本:2.7 一、爬虫入门 ...

  • Python爬虫学习之小结(一)

    到目前为止,Python爬虫学习已经写了八篇文章,分别是: Python爬虫学习(一)概述Python爬虫学习(二...

  • 爬虫入门

    为什么要学习爬虫? Python做爬虫优势 关于Python网络爬虫,我们需要学习的有: 什么是爬虫? 网络爬虫(...

  • python爬虫学习-day7-实战

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

  • Python 基础爬虫目录

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

  • python爬虫学习-day5-selenium

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

  • python爬虫学习-day6-ip池

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

  • python爬虫学习-day3-BeautifulSoup

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

网友评论

      本文标题:Python爬虫学习(一)

      本文链接:https://www.haomeiwen.com/subject/exnkfctx.html