#(2)
import requests
url = "https://www.google.cn/"
for i in range(20):
try:
r = requests.get(url, timeout = 30)
r.raise_for_status()
r.encoding = 'utf-8'
print(r.text)
except:
print('')
#(3)
import requests
from bs4 import BeautifulSoup
a = '''<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<h1>我的第一个标题</h1>
<p id="first">我的第一个段落。</p>
</body>
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
</html>'''
soup = BeautifulSoup(a)
print(soup.head,25)
print(soup.body)
print(soup.p)
print(soup.title.string,soup.h1.string,soup.p.string)