[問題] request.get.text抓到資料不全

看板Python作者 (費德勒5566)時間1年前 (2022/08/02 13:00), 1年前編輯推噓1(102)
留言3則, 2人參與, 1年前最新討論串1/1
主要是要抓這網站裡,每日的資料 https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564732650546663520&MmmID=616371300020211533 全部的headers都用上了 requests.text抓到的 仍停在<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"......這標籤 不曉得是缺了甚麼導致後面的html出不來 請版上高手賜教 程式碼如下: def GET_TAIPOWER_INFO(url): hs = {'Cookie': '_ga=GA1.3.1703053287.1657282388; _ga_M55J0R8SEB=GS1.1.1658290723.7.1.1658290760.0; ASP.NET_SessionId=covedx45ofvik1vsgjnpryi5; WebLang=','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36','Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7','Cache-Control': 'max-age=0','Connection': 'keep-alive','Host': 'branch.taipower.com.tw','sec-ch-ua':'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"','sec-ch-ua-mobile':'?0','sec-ch-ua-platform': 'Windows','Sec-Fetch-Dest': 'document','Sec-Fecth-Mode': 'navigate','Sec-Fetch-Site': 'none','Sec-Fetch-User': '?1','Upgrade-Insecure-Requsets': '1'} Params = {'SiteID': '564732650546663520','MmmID': '616371300020211533'} re = requests.get(url,headers=hs,params=Params) for i in range(10): if str(re.status_code) == '200': print('TaiPower page loaded.') break else: time.sleep(1) print(str(i)) print(str(re.text)) return('done') a=GET_TAIPOWER_INFO('https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx') print(a) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.137.242.21 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1659416450.A.D2F.html ※ 編輯: Federer5566 (114.137.242.21 臺灣), 08/02/2022 13:05:05

08/03 00:13, 1年前 , 1F
我稍微整理一下 發現 'Accept':mage 少了 ' 在前面
08/03 00:13, 1F

08/03 00:15, 1年前 , 2F
改成 'Accept':'mage ... 後就有抓到資料了
08/03 00:15, 2F

08/03 19:41, 1年前 , 3F
m大方法正確
08/03 19:41, 3F
文章代碼(AID): #1YwA-2ql (Python)