Thursday, August 2, 2018

Python - Reading Web Data From Python


Question 1

1
point

1. Question 1


Which of the following Python data structures is most similar to the value returned in this line of Python:
1
x = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')


file handle


socket


regular expression


dictionary


list
Question 2
1
point

2. Question 2


In this Python code, which line actually reads the data?
1
2
3
4
5
6
7
8
9
10
11
12
13
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()


mysock.recv()


socket.socket()


mysock.close()


mysock.connect()


mysock.send()
Question 3
1
point

3. Question 3


Which of the following regular expressions would extract the URL from this line of HTML:
1
<p>Please click <a href="http://www.dr-chuck.com">here</a></p>


href="(.+)"


href=".+"


http://.*


<.*>
Question 4
1
point

4. Question 4


In this Python code, which line is most like the open() call to read a file:
1
2
3
4
5
6
7
8
9
10
11
12
13
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()


mysock.connect()


import socket


mysock.recv()


mysock.send()


socket.socket()
Question 5
1
point

5. Question 5


Which HTTP header tells the browser the kind of document that is being returned?


Metadata:


ETag:


HTML-Document:


Content-Type:


Document-Type:
Question 6
1
point

6. Question 6


What should you check before scraping a web site?


That the web site allows scraping


That the web site returns HTML for all pages


That the web site only has links within the same site


That the web site supports the HTTP GET command
Question 7
1
point

7. Question 7


What is the purpose of the BeautifulSoup Python library?


It repairs and parses HTML to make it easier for a program to understand


It allows a web site to choose an attractive skin


It animates web operations to make them more attractive


It optimizes files that are retrieved many times


It builds word clouds from web pages
Question 8
1
point

8. Question 8


What ends up in the "x" variable in the following code:
1
2
3
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')
x = soup('a')


A list of all the anchor tags (<a..) in the HTML from the URL


True if there were any anchor tags in the HTML from the URL


All of the externally linked CSS files in the HTML from the URL


All of the paragraphs of the HTML from the URL
Question 9
1
point

9. Question 9


What is the most common Unicode encoding when moving data between systems?


UTF-16


UTF-128


UTF-64


UTF-32


UTF-8
Question 10
1
point

10. Question 10


What is the ASCII character that is associated with the decimal value 42?


*


^


!


/


+
Question 11
1
point

11. Question 11


What word does the following sequence of numbers represent in ASCII:
108, 105, 110, 101


ping


func


lost


line


tree
Question 12
1
point

12. Question 12


How are strings stored internally in Python 3?


UTF-8


Unicode


Byte Code


ASCII


EBCDIC
Question 13
1
point

13. Question 13


When reading data across the network (i.e. from a URL) in Python 3, what method must be used to convert it to the internal format used by strings?


upper()


find()


encode()


decode()


trim()

No comments:

Post a Comment