In [ ]:
!brew install python3
In [ ]:
!pip3 install jupyter
本次利用到的
第三方套件
In [ ]:
!pip3 install beautifulsoup4
In [ ]:
!pip3 install requests
計算機網路教過
去跟server要求資訊來分析
In [ ]:
In [ ]:
import requests
In [ ]:
response = requests.get("http://www.google.com.tw/search")
print(response)
In [ ]:
print(response.url)
print(response.text)
In [ ]:
response = requests.get("https://www.google.com.tw/search", params={"q":"嘉義大學"})
In [ ]:
response.url
In [ ]:
response.text
In [ ]:
response = requests.post("http://httpbin.org/post")
print(response)
In [ ]:
print(response.text)
In [ ]:
response = requests.post("http://httpbin.org/post", params={"p":"TEST"})
In [ ]:
print( response.text )
In [ ]:
response = requests.get( "https://upload.wikimedia.org/wikipedia/commons/8/84/HTML.svg", stream = True )
chunk_size = 1024
with open( "./img.svg", "wb" ) as file:
for chunk in response.iter_content(chunk_size):
file.write(chunk)
In [ ]:
from bs4 import BeautifulSoup
In [ ]:
html = """
<html>
<head>
<title>
The Link Test
</title>
</head>
<body>
<p class="title">
<b>
HaHa
</b>
</p>
<p class="links">
<a class="link" href="http://www.google.com" id="link1">Google</a>
<br>
<a class="link" href="http://www.ncyu.edu.tw" id="link2">NCYU</a>
<br>
<a class="link" href="http://www.ncyu.edu.tw/csie" id="link2">CSIE</a>
</p>
<p class="links">
...
</p>
</body></html>
"""
In [ ]:
soup = BeautifulSoup(html, "html.parser")
In [ ]:
soup.title.string
In [ ]:
soup.p
In [ ]:
soup.find_all('a')
In [ ]:
soup.find_all('a', id="link1")
In [ ]:
soup.find_all('a', id=True)
In [ ]:
soup.find_all('a', class_='link')
In [ ]:
soup.find_all('a', attrs={"class":"link"})