zoukankan      html  css  js  c++  java
  • Python 对网页操作的方法, urllib ;requests

    对http发起请求,获取请求的返回值,返回的是字符串形式的,

    jason数据(类似字典,列表的字符串)

    XML

    HTML

    方法一:

    使用 urllib模块。

    from urllib import request

    # f = request.urlopen("https://www.cnblogs.com/xuwenwei/p/14402832.html")
    # f = request.urlopen("https://qq.ip138.com/weather/jiangsu/KunShan.htm")
    f = request.urlopen("http://www.weather.com.cn/adat/sk/101050101.html")
    # f = request.urlopen("http://www.weather.com.cn/html/province/guangdong.shtml")
    result = f.read().decode('utf-8')
    print(result)
    print(type(result))


    方法二:
    使用 requests 模块
    import requests
    
    respons = requests.get("http://www.weather.com.cn/adat/sk/101050101.html")
    respons.encoding = 'utf-8'
    result = respons.text
    print(result)
    print(type(result))
  • 相关阅读:
    c++ struct 使用
    c++数组、字符串操作
    c++ List、Vector、Stack、Queue使用
    十三、哈希表
    十二、234树
    十一、红黑树
    十、哈夫曼编码
    九、二叉树
    八、高级排序
    七、递归
  • 原文地址:https://www.cnblogs.com/xuwenwei/p/14406431.html
Copyright © 2011-2022 走看看