-
Notifications
You must be signed in to change notification settings - Fork 0
/
week 4 quiz
56 lines (47 loc) · 1.87 KB
/
week 4 quiz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
1.Which of the following Python data structures is most similar to the value returned in this line of Python:
x = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
Ans:file handle
2.In this Python code, which line actually reads the data:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print(data.decode())
mysock.close()
Ans:mysock.recv()
3.Which of the following regular expressions would extract the URL from this line of HTML:
<p>Please click <a href="http://www.dr-chuck.com">here</a></p>
Ans:http://.*
4.In this Python code, which line is most like the open() call to read a file:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print(data.decode())
mysock.close()
Ans:mysock.connect( )
5.Which HTTP header tells the browser the kind of document that is being returned?
Ans:Content-Type:
6.What should you check before scraping a web site?
Ans:That the web site allows scraping not That the web site returns HTML for all pages
7.What is the purpose of the BeautifulSoup Python library?
Ans:It repairs and parses HTML to make it easier for a program to understand
8.What ends up in the "x" variable in the following code:
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')
x = soup('a')
Ans:A list of all the anchor tags (<a..) in the HTML from the URL
9.What is the most common Unicode encoding when moving data between systems?
Ans:UTF-8
10.What is the ASCII character that is associated with the decimal value 42?
Ans:*