Window.opener (omit write as opener) to refer to a.html, including A.html's document and other objects, to manipulate the contents of a.html.If this reference fails, then NULL is returned. Therefore, before invoking the opener object, you should first determine whether the object is null, otherwise the "object is empty or does not exist" JS error.Add a little bit about the difference between Window.opener
the cookie for login, and then directly post data to the login address.
First, use the packet capture tool or Firefox or Google Chrome to analyze the post request and header information on the login page. Take Google as an example.
It can be seen that the url to post is not the accessed page, but http: // 202.115.80.153/default2.aspx,
The TXT username and TextBox2 usernames and passwords in the form data to be submitted are respectively.
Now go directly to the key part of the code !!
Import u
This article mainly introduces how to log on to and post a message using python. It involves URL simulated login and cookie usage skills and has some reference value, for more information about how to log on to Douban using python and post it, see the example in this article. Share it with you for your reference. The details are as follows:
Use of urllib, urllib2, and cookielib
Log on to Douban. Because there is a verification code, you can download the verification code image to the same direc
In Python, the cookielib Library (http. cookiejar in python3) provides client support for storing and managing cookies. The following is an example. The main function of this module is to provide objects that can store cookies. This module captures cookies and resends them in subsequent connection requests. It can also be used to process files containing cookie data.
This module provides the following objects: CookieJar, FileCookieJar, MozillaCookieJar, and LWPCookieJar.
1. CookieJar
CookieJar
)>>> Opener = urllib2.build _ opener (handler)>>> Opener. open ('HTTP: // www.google.com.hk ') The cookie used to access google has been captured.
Let's take a look at the following:Copy codeThe Code is as follows:>>> Print cookie
It seems to be a set of Cookie instances. Cookie instances have attributes such as name, value, path, and expires:
Copy codeThe Code i
update;Opener Open the window of the current window;The parent points to a window that contains another window (used by the framework);Screen display-related information, such as height/width (in pixels;)Self indicates the current window;Status describes the temporary information that is caused by user interaction;Top contains the topmost window of a particular window (used by the framework);Windows indicates the current window, which is equivalent t
obtain page information based on the URL is solved. To solve this problem, you need to use HTTP client programming. This is also the problem solved in the next section.Urllib2: HTTP client Programming
There are several libraries in Python that can implement HTTP client programming, such as httplib, urllib, and urllib2. Urllib2 is used because it is powerful, easy to use, and can easily use HTTP proxy.
Using urllib2 to create an HTTP connection and obtain the page is very simple, only three step
1st Methods
The window to be opened is about.htm.
Script Language
=
Javascript
>
Function
Openwin (){Newwin
=
Zookeeper open('about.htm', 'login', 'location
=
No, Toolbar
=
No, status
=
Yes, resizable
=
No, scrollbars
=
No, menubar
=
No, directories
=
No ')Newwin. moveTo (
-
3
,
-
3
);Newwin. resizeTo (screen. availwidth
+
6
, Screen. availheight
+
6
);Window. Opener
=
Nu
. releaseevent (event)
Window. releaseevent (Event 1 | event 2 |... | Event n)
Function: release captured events passed in by parameters. These events are set by the window. captureevent method. The releasable events are the same as those of captureevent.
29. routeevent
Syntax format: window. releaseevent (event)
Function: transfers all captured events to the standard event handling method for handling. The events that can be transferred are the same as those of captureevent.
30. scroll event
Sy
Proficient in the use of open, close, alert, confirm, prompt, setTimeout, cleartimeout, setinterval, clearinterval, moveBy, resizeBy, and scrollby methods of window objectsMeasure the test taker's knowledge about how to use the moveTo, resizeTo, scrollto, and print methods of window objects.Familiar with the use of window objects in the status, location, name, self, and opener attributes of window objects is one of the top JavaScript objects on the cl
common method is to add the User-agent request header, impersonating a browser request, to coax the article server, because some servers do not allow program access.The latter two parameters are generally not used, no longer introducereturn valueA Request object4, Urllib2. Openerdirector classWhen you get a URL, you need to use a opener (Openerdirector). Normally we always use the default opener, which is
Brief introductionAlthough the Cookiejar module is capable of setting a cookie for a request, its cookie is stored in memory and needs to be reset each time.This derives a subclass of it---filecookiejar, which can store the cookie in a file and then use it directly.Save the sample cookieFrom urllib import request,parsefrom http import cookiejar# Create Filecookiejar Instance object # It takes a parameter, both the location of the cookie to save the filename = ' Cookie.txt ' cookie = Cookiejar. F
the content of a site, on the other side of the site, the display is not our real IP address, but the IP address of the proxy server)defUse_proxy (proxy_addr,url):ImportUrllib.request Proxy=urllib.request.proxyhandler ({'http':p roxy_addr}) Opener=Urllib.request.build_opener (Proxy,urllib.request.httphandler) Urllib.request.install_opener (opener) data =urllib.request.urlopen (URL). read (). Decode ('UTF8'
'})Opener=urllib.request.build_opener (Handler)The Urllib.request.install_opener (opener) #安装opener作为urlopen () uses the global URL opener, which is the opener object that is installed when Urlopen () is called later.Response=urllib.request.urlopen (' http://www.google.com
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.