How to Use python to shield some basic functions in html?
There are countless reasons for parsing data, as are related tools and techniques. However, when you need to use this data to do something new, it may not be enough even if there is a "suitable" tool. This concern also exists for the integration of heterogeneous data sources. A suitable tool for doing this should be a programming language sooner or later.
Oracle provides powerful utilities for loading, processing, and detaching data. SQL * Loader, Data Pump, External table, Oracle Text, and regular expressions all provide these functions. However, people often need to do something outside the database (or, if it is trivial, you may not have the necessary database permissions ).
Python can be used for high-level and effective data parsing. However, a large number of standard libraries and multiple modules provided free of charge on the Internet can be used to process data logic without the need to manually analyze bytes.
I just sent a small hacker in the address bar to unmask the web page. Recently I learned python and wrote something quite simple. I can also do this.
- #-*-Coding: UTF-8 -*-
- "Author: hujinpu """
- "Http://docs.python.org/lib/module-urllib.html """
- Import urllib
- Urls = {'blocked webpage address ': 'downloadtomycomputer.htm '}
- For url in urls:
- Filename = urls [url]
- Urllib. urlretrieve (url, filename)
- F = open (filename, 'R ')
- Content = f. read ()
- F. close ()
- Newfilename = "new _" + filename
- F = open (newfilename, 'w ')
- F. write (content + "<script> document. onselectstart = document. oncontextmenu = document. onmousedown = document. onkeydown = function () {return true ;}; </script> ");
- F. close ()
Here, urls is a dictionary that can write a lot of urls you want to conquer.
Python Interaction
In many cases, you may want to allow your program to interact with users (possibly yourself. You will get the input from the user and print some results. We can use raw_input and input statements to complete these functions respectively. You can also use a variety of str (string) classes for output. For example, you can use the convert ust method to obtain a string that is right-aligned with a certain width. Use help (str) to obtain more details.
Another common input/output type is processing files. The ability to create, read, and write files is required by many programs.
File:
You can create a file class object to open a file and use the read, readline, or write methods of the file class to read and write the file properly. The ability to read and write files depends on the mode specified when you open the file. Finally, when you complete file operations, you call the close method to tell Python that we have used the file.
#! /Usr/bin/python
# Tue Jan 8 21:25:42 CST 2013
Poem = '''\\
Programming is fun
When the work is done
If you wanna make your work also fun:
Use Python!
'''
F=file('poem.txt ', 'w ')
F. write (poem)
F. close ()
F=file('poem.txt ')
While True:
Line = f. readline ()
If len (line) = 0:
Break
Print line,
F. close ()
The file opening mode can be read ('R'), write ('W'), or append ('A ').
Write can only write strings.
Storage
Python provides a standard module called pickle. Using it, You can store any Python object in a file, and then you can take it out completely. This is called a persistent storage object.
Another module, cPickle, has the same functions as the pickle module, but is written in C language so it is faster than pickle.
#! /Usr/bin/python
# Wed Jan 9 17:40:54 CST 2013
Import cPickle as p
Shoplistfile = 'shoplist. data'
Shoplist = ['apple', 'egg', 'bana']
F = file (shoplistfile, 'w ')
P. dump (shoplist, f)
F. close
F = file (shoplistfile)
Storedlist = p. load (f)
Print storedlist
Use the import... as syntax. So that we can use the module name of the heel segment.
Python also handles exceptions. Use try .. handle T for exception handling. We place the common statements in the try block and the error handling statement in the limit t block.
We place all statements that may cause errors in the try block, and then process all errors and exceptions in the limit t clause/block. The limit t clause can specifically handle a single error or exception, or a group of errors/exceptions included in parentheses. If no error or Exception name is provided, it will handle all errors and exceptions. Each try clause must have at least one correlated limit t clause.
Try .. finally
What should you do if you want to close the file regardless of whether an exception occurs? This can be done using finally blocks. Note: In a try block, you can use the limit t clause and the finally block. If you want to use them at the same time, you need to embed one into another.
Run time. sleep (2) in the program to rest the program. It must be added to the time module.
The Python standard library is installed with Python and contains a large number of useful modules for machines.