欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

Coursera课程Python for everyone:Quiz: Reading Web Data From Python

发布时间:2025/3/21 python 55 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。