- 帖子
- 2035
- 主題
- 24
- 精華
- 0
- 積分
- 2031
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office2010
- 閱讀權限
- 100
- 性別
- 男
- 註冊時間
- 2012-3-22
- 最後登錄
- 2024-2-1
|
14#
發表於 2017-2-9 19:52
| 只看該作者
本帖最後由 c_c_lai 於 2017-2-9 19:59 編輯
回復 11# VBALearner
請教為何會無 select 屬性?
我輸入內容是否有誤?- import requests
- import time
- from bs4 import BeautifulSoup
- 主提單號碼=['160-69306532','608-10318674']
- with requests.session() as r:
- res = r.get('https://accs.tradevan.com.tw/accsw-bin/APACCS/userLoginAction.do?userid=GUEST&password=GUEST')
- for code in 主提單號碼:
- print('主提單號碼:',code, '\n')
- payload = {'mawb_no':code,'查詢':'查詢'}
- res = r.post("https://accs.tradevan.com.tw/accsw-bin/APACCS/clmMergeQueryAction.do", data=payload)
- res.encoding = "big-5"
- html = BeautifulSoup(res.text,"html.parser")
- for tr in html.body.select('table')[4].select('tr')[1:]: #請詳閱w3school裡有關HTML的Table標籤知識,就能知道這裡在做啥
- data = [] #建立陣列
- for td in tr.select('td'):
- data.append(td.text.strip())
- if td == tr.select('td')[len(tr.select('td'))-1]: #這裡有下一個POST所需的資訊 (payload),透過觀察網頁原始碼得知
- print('第二次POST的資料:',td,'\n')
- print('摘要資訊:',data, '\n') #第一次查詢得到的摘要資料
複製代碼 |
|