using python to access web data week 3 assignment
Networks and Sockets (Chapter 12)
1. What do we call it when a browser uses the HTTP protocol to load a file or page from a server and display it in the browser?
- DECNET
- Internet Protocol (IP)
- IMAP
- SMTP
- The Request/Response Cycle
2. Which of the following is most similar to a TCP port number?
- A telephone number
- A street number in an address
- The GPS coordinates of a building
- A telephone extension
- The distance between two locations
3. What must you do in Python before opening a socket?
- import tcp-socket
- import tcp
- open socket
- _socket = true
- import socket
4. Which of the following TCP sockets is most commonly used for the web protocol (HTTP)?
- 80
- 119
- 23
- 22
- 25
5. Which of the following is most like an open socket in an application?
- An “in-progress” phone conversation
- Fiber optic cables
- The wheels on an automobile
- The chain on a bicycle
- The ringer on a telephone
6. What does the "H" of HTTP stand for?
- Hyperspeed
- Simple
- wHolsitic
- Manual
- HyperText
7. What is an important aspect of an Application Layer protocol like HTTP?
- How long do we wait before packets are retransmitted?
- How much memory does the server need to serve requests?
- Which application talks first? The client or server?
- What is the IP address for a domain like www.dr-chuck.com?
8. What are the three parts of this URL (Uniform Resource Locator)?
http://www.dr-chuck.com/page1.htm
- Protocol, host, and document
- Document, page, and protocol
- Page, offset, and count
- Host, offset, and page
- Protocol, document, and offset
9. When you click on an anchor tag in a web page like below, what HTTP request is sent to the server?
<p>Please click <a href=”page1.htm”>here</a>.</p>
- GET
- POST
- PUT
- DELETE
- INFO
10. Which organization publishes Internet Protocol Standards?
- IETF
- LDAP
- IMS
- SCORM
- SIFA
Understanding the Request / Response Cycle
Exploring the HyperText Transport Protocol You are to retrieve the following document using the HTTP protocol in a way that you can examine the HTTP Response headers. http://data.pr4e.org/intro-short.txt There are three ways that you might retrieve this web page and look at the response headers: Preferred: Modify the socket1.py program to retrieve the above URL and print out the headers and data. Make sure to change the code to retrieve the above URL - the values are different for each URL. Open the URL in a web browser with a developer console or FireBug and manually examine the headers that are returned. Enter the header values in each of the fields below and press "Submit". Last-Modified: ETag: Content-Length: Cache-Control: Content-Type:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect((‘data.pr4e.org’, 80))
cmd = ‘GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n’.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if len(data) < 1:
break
print(data.decode(), end=”)
mysock.close()