zoukankan      html  css  js  c++  java
  • 爬虫练习

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    import urllib.request#这里必须要加request
    import urllib.parse
    import requests
    import sys
    #sys.Setdefaultencoding('utf-8')
    import urllib
    import json
    import time
    from bs4 import BeautifulSoup
    #发起GET请求
    # url = 'http://kaoshi.edu.sina.com.cn/college/scorelist?tab=batch&wl=1&local=2&batch=&syear=2013'
    # response = urllib.request.urlopen(url=url)
    # result = response.read().decode('utf-8')#解码后可以正常输出
    # print(result)
    #发起POST请求
    url = "http://shuju.wdzj.com/plat-info-59.html"
    data = urllib.parse.urlencode({'type1':'x','type2':0,'status':0}).encode('utf-8')
    request = urllib.request.Request(url=url,data=data)
    #opener = urllib.build_open(urllib.HTTPCookieProcessor()) #跟上述差不多,只是了一个data
    response = urllib.request.urlopen(request)
    result = response.read().decode('utf-8')
    print(result)
    result = result.replace('<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">', '')
    result = result.replace('</pre></body></html>', '')
    for key in json.loads(result,strict=False).keys():
        print(key)
    #报错:json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)
  • 相关阅读:
    flask笔记(引用)
    三元表达式(列表解析+if)
    生成器
    闭包、装饰器、高阶函数
    列表的解压和取值
    模块
    时间操作
    day16 css, dom
    day 15 html(2) css,javascript,dom
    day 14 html
  • 原文地址:https://www.cnblogs.com/lifengwu/p/9858998.html
Copyright © 2011-2022 走看看