Coursera课程Python for everyone:Quiz: Reading Web Data From Python
Reading Web Data From Python
8?試題
1.?Which of the following Python data structures is most similar to the value returned in this line of Python:
x = urllib.urlopen('http://www.py4inf.com/code/romeo.txt')dictionary
regular expression
file handle
socket
list
2.?In this Python code, which line actually reads the data?
import socket mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.connect(('www.py4inf.com', 80)) mysock.send('GET http://www.py4inf.com/code/romeo.txt HTTP/1.0\n\n') while True:data = mysock.recv(512)if ( len(data) < 1 ) :breakprint data mysock.close()mysock.recv()
socket.socket()
mysock.close()
mysock.connect()
mysock.send()
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>href="(.+)"
href=".+"
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(('www.py4inf.com', 80)) mysock.send('GET http://www.py4inf.com/code/romeo.txt HTTP/1.0\n\n') while True:data = mysock.recv(512)if ( len(data) < 1 ) :breakprint data mysock.close()mysock.connect()
import socket
mysock.recv()
mysock.send()
socket.socket()
5.?Which HTTP header tells the browser the kind of document that is being returned?
Content-Type:
Document-Type:
HTML-Document:
ETag:
Metadata:
6.?What should you check before scraping a web site?
That the web site supports the HTTP GET command
That the web site only has links within the same site
That the web site returns HTML for all pages
That the web site allows scraping
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 animates web operations to make them more attractive
It builds word clouds from web pages
It optimizes files that are retrieved many times
It allows a web site to choose an attractive skin
8.?What ends up in the "x" variable in the following code:
html = urllib.urlopen(url).read() soup = BeautifulSoup(html) 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
總結
以上是生活随笔為你收集整理的Coursera课程Python for everyone:Quiz: Reading Web Data From Python的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Coursera课程Python for
- 下一篇: Coursera课程Python for