Python web crawler notes (ix)

Source: Internet
Author: User
Tags gettext ftp protocol python web crawler

4.1.1 Urllib2 and Urllib are two different modules.

The simplest of URLLIB2 is to use the Urllie2.urlopen function as follows

Urllib2.urlopen (Url[,data[,timeout[,cafile[,capath[,cadefault[,context]]]) to open HTTP HTTPS according to document Urllib2.urlopen FTP protocol URL link address, starring the use of the HTTP protocol, his parameters to the beginning of the CA is related to authentication, infrequently used, the data parameter is the Post method to submit the URL when used, commonly used is the timeout parameter, the URL parameter is to submit the network address full name, the front end is the protocol name, The backend is the port number, and timeout is the time-out setting,

The function return object has three additional use methods, the Geturl () function returns the response URL information, commonly used in the case of redirection, the info () function returns the basic information of response, the GetCode () function returns the response status code, 200 successful, 404 page does not exist, 503 server is temporarily unavailable,

At first, the imported module was URLLIB2, but there was an error running because the Urllib module used in the version above python3.0 was the Urllib.request module. The word module should be imported in response. There are also differences in print, with the string type used in write. Changes are also to be made. To execute correctly.

It is also important to note that the VI used in Linux must be preceded by a declaration statement, if the module to be called must import a module of the response,

#!/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) {

}
}

}

Python web crawler notes (ix)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.