4.1.1 urllib2 和urllib是两个不一样的模块

urllib2最简单的就是使用urllie2.urlopen函数使用如下

urllib2.urlopen(url[,data[,timeout[,cafile[,capath[,cadefault[,context]]]]]])  按照文档urllib2.urlopen可以打开HTTP HTTPS FTP协议的URL链接地址,主演使用HTTP协议,他的参数以ca开头的都是跟身份验证有关,不常使用,data参数是post方法提交URL时使用,常用的是timeout参数,url参数是提交网络地址全称,前端是协议名,后端是端口号,timeout是超时时间设置,

函数返回对象有三个额外使用方法,geturl()函数返回的response的url信息,常用于重定向的情况,info()函数返回的response的基本信息, getcode()函数返回的response的状态代码,200成功, 404页面不存在, 503服务器暂时不可用,

刚开始,导入得模块是urllib2,但是运行出错,因为urllib在python3.0以上的版本使用的模块是urllib.request模块。响应的就要导入词模块。在print中也存在差别,write中使用的是String类型。也要做更改。才能正确执行。

另外就是要说明一点,在Linux中使用的vi 进行编程 前面必须添加声明语句,如果要调用模块必须导入响应的模块、

#!/usr/bin/env python
#-*- coding: utf-8 -*-

package com.tian;
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.Font;
import java.awt.event.*;
public class QuizCardBuilder {
    private JTextArea question;
    private JTextArea answer;
    private JFrame frame;
//    private ArrayList<QuizCard> cardList;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        QuizCardBuilder builder=new QuizCardBuilder();
        builder.go();
    }
    public void go(){
        frame=new JFrame("Quiz Card Builder");
        JPanel mainPanel=new JPanel();
        Font bigFont=new Font("sanserif",Font.BOLD,23);
        question=new JTextArea(6,23);
        question.setLineWrap(true);
        question.setWrapStyleWord(true);
        question.setFont(bigFont);
        JScrollPane qScroller=new JScrollPane(question);
        qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        answer=new JTextArea(6,20);
        answer.setLineWrap(true);
        answer.setWrapStyleWord(true);
        answer.setFont(bigFont);
        JScrollPane aScroller=new JScrollPane(answer);
        aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        JButton nextbutton=new JButton("next button");
//        cardList=new ArrayList<QuizCard>();
        JLabel qLabel=new JLabel("Question");
        JLabel aLabel=new JLabel("Answer");
        mainPanel.add(qLabel);
        mainPanel.add(qScroller);
        mainPanel.add(aLabel);
        mainPanel.add(aScroller);
        mainPanel.add(nextbutton);
        nextbutton.addActionListener(new NextCardListener());
        JMenuBar menuBar=new JMenuBar();
        JMenu fileMenu=new JMenu("File");
        JMenuItem newMenuItem=new JMenuItem("new");
        JMenuItem saveMenuItem=new JMenuItem("save");
        newMenuItem.addActionListener(new NewMenuListener());
        saveMenuItem.addActionListener(new SaveMenuListener());
        fileMenu.add(newMenuItem);
        fileMenu.add(saveMenuItem);
        fileMenu.add(fileMenu);
        menuBar.add(fileMenu);
        frame.setJMenuBar(menuBar);
        frame.getContentPane().add(BroderLayout,mainPanel);
        frame.setSize(200,200);
        frame.setVisible(true);
    }
    
    public class  NextCardListener implements ActionListener{
        public void actionPerformed(ActionListener ev){
            QuizCard card=new QuizCard(question.getText(),answer.getText());
            cardList.add(card);
            clearCard();
        }
    }
    public class SaveMenuListener implements ActionListener{
         public void actionPerformed(ActionListener ev){
            
         }
    }

}

转载于:https://www.cnblogs.com/xinxianquan/p/8678815.html

python网络爬虫笔记(九)相关推荐

  1. Python 网络爬虫笔记11 -- Scrapy 实战

    Python 网络爬虫笔记11 – Scrapy 实战 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接:Py ...

  2. Python 网络爬虫笔记10 -- Scrapy 使用入门

    Python 网络爬虫笔记10 – Scrapy 使用入门 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接: ...

  3. Python 网络爬虫笔记9 -- Scrapy爬虫框架

    Python 网络爬虫笔记9 – Scrapy爬虫框架 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接:Py ...

  4. Python 网络爬虫笔记8 -- 股票数据定向爬虫

    Python 网络爬虫笔记8 – 股票数据定向爬虫 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接:Pyth ...

  5. Python 网络爬虫笔记6 -- 正则表达式

    Python 网络爬虫笔记6 – 正则表达式 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接:Python网 ...

  6. Python 网络爬虫笔记5 -- Beautiful Soup库实战

    Python 网络爬虫笔记5 – Beautiful Soup库实战 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. ...

  7. Python 网络爬虫笔记4 -- 信息标记与提取

    Python 网络爬虫笔记4 – 信息标记与提取 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接:Pytho ...

  8. Python 网络爬虫笔记3 -- Beautiful Soup库

    Python 网络爬虫笔记3 – Beautiful Soup库 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程 ...

  9. Python 网络爬虫笔记2 -- Requests库实战

    Python 网络爬虫笔记2 – Requests库实战 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接:P ...

  10. Python 网络爬虫笔记1 -- Requests库

    Python 网络爬虫笔记1 – Requests库 Python 网络爬虫系列笔记是笔者在学习嵩天老师的<Python网络爬虫与信息提取>课程及笔者实践网络爬虫的笔记. 课程链接:Pyt ...

最新文章

  1. ModuleNotFoundError: No module named 'tools.nnwrap' pytorch 安装
  2. JZOJ 5461 购物 —— 贪心
  3. 【机器视觉学习笔记】双线性插值实现图片任意角度旋转(C++)
  4. “智享未来 知行合一”,开为科技助力企业开启人工智能新时代
  5. springmvc从request中获取body的数据的方法
  6. 金属激光切割机行业调研报告 - 市场现状分析与发展前景预测
  7. Ecology 建模表单 数据库字段与页面字段对应关系显示
  8. kafka+线程池+Runnable
  9. 痞子衡嵌入式:如果你正在量产i.MX RT产品,不妨试试这款神器RT-Flash
  10. android 的mvp架构,老生常谈Android的MVP架构
  11. 秘密行动倒计时丨DC86021行动指挥部致全体极客伙伴的一封密信
  12. openlayer制作专题图
  13. 又是一年双11,神棍节终于来啦
  14. 抢先入驻皮皮虾APP社区 红利初期第一批操作者绝对有肉吃
  15. ecshop 添加会员头像功能
  16. 从零学习Nginx配置文件,呕心沥血w字长文
  17. c语言 linux系统 delay,Linux下实现秒级定时任务的两种方案
  18. 西安外国语大学计算机语言学,2017年西安外国语大学语言学及应用语言学832现代汉语考研题库...
  19. 程序员手疼7年以为就是“键盘手”没在意!竟是骨肿瘤 ....
  20. MySQL 大表性能优化

热门文章

  1. 源码安装php时出现configure: error: xml2-config not found. Please check your libxml2 installation...
  2. GitLab 严重漏洞可用于接管用户账户
  3. 谷歌详述 Zoom 客户端和MMR 服务器中的两个0day
  4. 西门子 PLM 产品被曝数十个漏洞,可导致代码执行后果
  5. 聚焦BCS|新华网:2020年北京网络安全大会开幕
  6. 开源审计的最佳时机是什么时候?
  7. MITRE 发布工控系统的 ATTCK 框架
  8. oracle 移动数据文件(装)
  9. 如何查看Oracle数据库字符集 尚未研究
  10. Second Highest Salary --leetCode