There are three main ways to access a Web page using python: Urllib, Urllib2, HttplibUrllib simple, relatively weak function, Httplib simple and powerful, but does not support session1. The simplest page access (get the server-side response package)Res=urllib2.urlopen (URL)Print Res.read ()2. Plus the data to get or postdata={"name": "Hank", "passwd": "HJZ"}Urllib2.urlopen (URL, urllib.urlencode (data))3. Add the HTTP headerheader={"user-agent": "mozilla-firefox5.0"}Urllib2.urlopen (URL, urllib.
In front of the Urllib2 simple introduction, the following collation of a part of the use of urllib2 details.
setting of 1.Proxy
URLLIB2 uses environment variable HTTP_PROXY to set HTTP proxy by default.If you want to explicitly control the proxy in your program without being affected by the environment variables, you can use the proxy.Create a new test14 to implement a simple proxy demo:
Copy Code code as follows:
Import Urllib2
Enable_proxy = True
Proxy_handler = Urllib2
solve the problem. No, it's a compressed thing, it's hard to solve. I'll do it myself, anyway, now the Compression class library is a lot, however, I finally chose the Windows FCI/FDI interface, it can directly generate the CAB format compression package, and now popular compression software can support it. There are other reasons to choose it: 1. I have used it before using C #, there is a ready-made packaging library (C language version, the speed is good), 2. Because it is the interface with
) ‘
Referrer=‘http://www.xxxxxx.com/‘
Postdata = {‘username‘ : ‘qiye’,
‘password‘ : ‘qiye_pass’}
# Write user_agent, referer to header information
Headers={‘User-Agent’:user_agent,‘Referer‘:referer}
Data = urllib.urlencode(postdata)
Req = urllib2.Request(url, data,headers)
Response = urllib2.urlopen(req)
Html = response.read()
3 Cookie Processing
Urllib2 the processing of cookies is also automatic, using the Cookiejar function for the management of cookies, if you need to get th
, we can use Window.opener (omit write as opener) to reference a.html, including a.html document and other objects, manipulate a.html content.If this reference fails, then NULL is returned. Therefore, before calling the opener object, you must first determine whether the object is null, otherwise the "object is empty or does not exist" JS error.Example--------------------------------Opener.html-------------
If you want to associate a specified window, you can use the target attribute of the
The previous link opens a new window named review. The following links use JavaScript to produce the same effect:
Onclick = "window. Open ('HTTP: // www.intel.com/', 'review'); Return false"> intel
As you can see, it is very easy to assign a name to a new window. However, what if I name an existing window or a window generated by a user?
The name attribute of the window object allows you to set the name of a
# create a password manager 6 7 password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() 8 9 # Add the username and password.10 11 # If we knew the realm, we could use it instead of None.12 13 top_level_url = "https://www.python.org/"14 15 password_mgr.add_password(None, top_level_url, 'rekfan', 'xxxxxx')16 17 handler = urllib.request.HTTPBasicAuthHandler(password_mgr)18 19 # create "opener" (OpenerDirector instance)20 21
Super.ontouchevent (EV) is returned, the default processing logic is the same as the return false.Service, two startup modes and features, how to communicate with activity
Reference Blog, article: Http://www.jianshu.com/p/2fb6eb14fdec
= = Use start to start the service = =Steps:
To define a class to inherit a service
Configure the service in the Manifest.xml file
Start with the StartService (Intent) method of the context
Call the StopService (Intent) method to
multiple accesses to the same IP over a short period of time
(1) Delayed access time ( not recommended )(2) AgentThe ① parameter is a dictionary {' type ': ' proxy IP: port number '}Proxy_support = Urllib.request.ProxyHandler ({})② customizing, creating a openerOpener = Urllib.request.build_opener (proxy_support)③A. installation openerUrllib.request.install_opener (opener)B. call openerOpener.open (URL)(direct search for proxy IP is ok)Import Ur
to reach a server. ')
Print (' Reason: ', E.reason)
elif hasattr (E, ' Code '):
print (' The server couldn ' t fulfill the request. '
) Print (' Error code: ', E.code)
else:
print ("good!")
Print (Response.read (). Decode ("UTF8"))
8, HTTP authentication
#! /usr/bin/env python3
Import urllib.request
# Create a password manager
password_mgr = Urllib.request.HTTPPasswordMgrWithDefaultRealm ()
# ADD the username and password.
# If We knew the realm, we could use it instead of None.
To
" extension in the "My programs" and "SRC" directories to the compressed archive "Archive.zip"-t{type}: Set Type of archive Specifies the format of the compressed package (zip, 7z, RAR, Cab, gzip, bzip2, TAR)-V{SIZE}[B|K|M|G]: Create Volumes Specify the sub-volume size-p{password}: Set Password specify password-w[{path}]: Assign work directory. Empty path means a temporary directory temporary working directory-ssw:compress shared files compresses a fi
How to get command Help information on Linux system and chapter partition of man document1. Order--Help2. Man commandThe latter more detailedFirst help the middle angle brackets The expression within square brackets (the character between "[" and "]") is optional (the parentheses are removed when the command is written).The expression within the angle brackets (the character between "[" and "]") is an expression that must be replaced (and the parentheses are removed).An ellipsis indicates that t
://www.rarsoft.com/rar/rarlinux-3.6.0.tar.gz7z a 7z.7z*#7z Compression7z e 7z.7z#7z DecompressionUnzip Zip.zip#Unzip zipZip Zip.zip *#Compress zipXZ Compression Tool {-Z#compressed, you can use XZ directly when compressing-D#Unzip
POST!!Set _XSRF, ID, password Three magic weapon, we can launch post. Once the post is launched, we log on to the server and the server sends US Cookies. It would be a hassle to deal with cookies, but the Python Http.cookiejar library gives us a convenient solution, so long as a httpcookieprocessor is put in when the opener is created, the cookie thing is not It's in our possession. The following code shows this point.12345678910111213Import Http.coo
It's just an article. It's not guaranteed to be usable if you keep an archive.
Use existing cookies to access the website
Import cookielib, urllib2
Ckjar = cookielib. cookillacookiejar (OS. Path. Join ('C: \ Documents and Settings \ Tom \ Application Data \ Mozilla \ Firefox \ profiles \ h5m61j1i. default ','Cookies.txt '))
Req = urllib2.request (URL, postdata, header)
Req. add_header ('user-agent ',\'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1 )')
Methods and attributes of js-window objects
Hxpd published on 21:58:18 proficient in the use of open, close, alert, confirm, prompt, setTimeout, cleartimeout, setinterval, clearinterval, moveBy, resizeBy, and scrollby methods of window objects
Measure 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
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.