Python Session 11j Updated
Python Session 11j Updated
Objectives
Findall ()
Extracts data from a string.
Returns all non-overlapping matches of pattern in string.
Scans data from left-to-right and returns exact match.
Returns a list of groups if one or more groups found.
Output:
[‘[email protected]',
‘[email protected]']
Combining, Searching
and Extracting
Answer: ['accomplished',
'attempt']
Activity
Write a program to simulate the operation of the grep command in Unix. Ask the user to
enter a regular expression and count the number of lines that matched the regular
expression.
Http Request
Client Server
Http Response
Understanding Sockets
Sockets are much like a file except that it provides a two way
connection between two programs with a single socket
World’s Simplest Web Browser
We can manually send and receive data over HTTP using the
socket library in a simpler way using “urllib”.
“urllib” will retrieve the web page which you have indicated
and handles all of the http protocol and header details.
Output:
But soft what light through yonder window breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
Who is already sick and pale with grief
Just a Minute
Answer: urllib
Just a Minute
Answer: Socket
Activity
Write a socket program so that it counts the number of characters it has received and stops
displaying any text after it has shown 3000 characters. The program should retrieve the entire
document and count the total number of characters and display the count of the number of
characters at the end of the document.