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

作者: Federer5566 (費德勒5566)   2022-08-02 13:00:45
主要是要抓這網站裡,每日的資料
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)
作者: mikemike1021 (mike)   2022-08-03 00:13:00
我稍微整理一下 發現 'Accept':mage 少了 ' 在前面改成 'Accept':'mage ... 後就有抓到資料了
作者: hanfadacai (沒有綽啦)   2022-08-03 19:41:00
m大方法正確

Links booklink

Contact Us: admin [ a t ] ucptt.com