---
# System prepended metadata

title: 2019/10/01

---

# 2019/10/01
- 使用 Python 實作 Dcard 爬蟲，並顯示出 Dcard 熱門板全部標題 (附程式碼)
- ![](https://i.imgur.com/bShn577.jpg)
- ![](https://i.imgur.com/unmIggm.jpg)
- ![](https://i.imgur.com/ya2lFr1.jpg)
    - 程式碼
    
    ```
    import requests
    from bs4 import BeautifulSoup
    import re
    a='https://www.dcard.tw/f'
    resp=requests.get(a)
    soup=BeautifulSoup(resp.text, 'html.parser')
    dcard_title=soup.find_all('h3',                 re.compile('Title__'))

    for index, item in enumerate(dcard_title):
    print("{0:2d}. {1}".format(index + 1,           item.text.strip()))


    ```
 

- 完成 Python **Script Homework** 練習 (附程式碼)
    ![](https://i.imgur.com/QthCiKb.png =500x) <- 這題 
    ![](https://i.imgur.com/4NFcIqr.jpg)
    ![](https://i.imgur.com/aOVExkp.jpg)
    ![](https://i.imgur.com/eQDI7S3.jpg) 
    - 程式碼
```
def is_int(str):
    try:
        int(str)
        return True
    except ValueError:
        return False
import requests
from bs4 import BeautifulSoup
r = requests.Session()
index = r.get('http://140.134.25.138:10022/index.php')
soup = BeautifulSoup(index.text,"html.parser")
#print(soup.prettify())
print('**********抓含有input的資料************')
a=soup.find_all('span')
b=soup.find_all('h1')
#print(b)
x=str(a[0])
y=str(a[1])
z=str(a[2])
print(x)
print(y)
print(z)
print('***********取出資料 運算input***********')
cal=[]
flag=0
for i in range(len(x)):
    if(x[i]=='>' and flag!=1):
        flag=1
    if(flag==1):
        if(x[i]!='>'and x[i]!='<'):
            cal.append(x[i])
        elif(x[i]=='<'):
            flag=0

for i in range(len(y)):
    if(y[i]=='>' and flag!=1):
        flag=1
    if(flag==1):
        if(y[i]!='>'and y[i]!='<'):
            cal.append(y[i])
        elif(y[i]=='<'):
            flag=0

for i in range(len(z)):
    if(z[i]=='>' and flag!=1):
        flag=1
    if(flag==1):
        if(z[i]!='>'and z[i]!='<'):
            cal.append(z[i])
        elif(z[i]=='<'):
            flag=0
print(cal)
for long in range(len(cal)):
    if(is_int(cal[long])==False):
        break
ID_1=0
ID_2=0
for i in range (long):
    if(i==0):
        ID_1=int(cal[i])
    else:
        ID_1=10*int(ID_1)+int(cal[i])
print('ID_1:'+str(ID_1))
for i in range (long+1,len(cal)):
    if(i==0):
        ID_2=int(cal[i])
    else:
        ID_2=10*int(ID_2)+int(cal[i])
print('ID_2:'+str(ID_2))
op=0
if(cal[long]=='+'):
    op=ID_1+ID_2
elif(cal[long]=='-'):
    op=ID_1-ID_2
elif(cal[long]=='*'):
    op=ID_1*ID_2
elif(cal[long]=='/'):
    op=ID_1/ID_2
print('Input='+str(op))
print('**********************')
print('接著就不斷給它input')
print('再用"CTF{NOT_THIS_ONE}"判斷是否找到解答')
print('寫了很久，但還是做不出來')
############################################
index = r.post('http://140.134.25.138:10022/index.php',data=data)
  
```
- 請說明GET跟POST的差別
-嚴格來說一般的表單可以用GET 直接傳遞，而需要保密的資料必須用POST 來處理，像是會員登入的帳號密碼。
前者表單參數與填寫內容可在URL 看到，後者透過HTTP Request 方式，故參數與填寫內容不會顯示於URL。
- 請說明HTTP跟HTTPS的差別
-後者較安全，HTTPS是經過加密的超文本傳輸協定，但HTTP以一般(非安全)模式在進行互動交談，所以內容有可能遭攔截竊聽。

- 截圖證明已解完 Source Code、Network、Redirect and Headers
-![](https://i.imgur.com/74BXgOX.jpg)
