python 爬取學(xué)信網(wǎng)登錄頁面的例子
我們以學(xué)信網(wǎng)為例爬取個人信息
**如果看不清楚
按照以下步驟:**
1.火狐為例 打開需要登錄的網(wǎng)頁–> F12 開發(fā)者模式 (鼠標(biāo)右擊,點擊檢查元素)–點擊網(wǎng)絡(luò) –>需要登錄的頁面登錄下–> 點擊網(wǎng)絡(luò)找到 一個POST提交的鏈接點擊–>找到post(注意該post中信息就是我們提交時需要構(gòu)造的表單信息)
import requests from bs4 import BeautifulSoup from http import cookies import urllib import http.cookiejar headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0', 'Referer':'https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check', } session = requests.Session() session.headers.update(headers) username = 'xxx' password = 'xxx' url = 'https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check' def login(username,password,lt,_eventId='submit'): #模擬登入函數(shù) #構(gòu)造表單數(shù)據(jù) data = { #需要傳去的數(shù)據(jù) '_eventId':_eventId, 'lt':lt, 'password':password, 'submit':u'登錄', 'username':username, } html = session.post(url,data=data,headers=headers) def get_lt(url): #解析登入界面_eventId html = session.get(url) #獲取 lt soup = BeautifulSoup(html.text,'lxml',from_encoding="utf-8") lt=soup.find('input',type="hidden")['value'] return lt lt = get_lt(url)#獲取登錄form表單信息 以學(xué)信網(wǎng)為例 login(username,password,lt) login_url = 'https://my.chsi.com.cn/archive/gdjy/xj/show.action' per_html = session.get(login_url) soup = BeautifulSoup(per_html.text,'lxml',from_encoding="utf-8") print(soup) for tag in soup.find_all('table',class_='mb-table'): print(tag) for tag1 in tag.find_all('td'): title= tag1.get_text(); print(title)
以上這篇python 爬取學(xué)信網(wǎng)登錄頁面的例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python+SeaTable實現(xiàn)計算兩個日期間的工作日天數(shù)
在實際的項目管理、任務(wù)管理、工作計劃等場景中,某些時間段會涉及雙休日、法定節(jié)假日,甚至還有公司自定義的工作時間安排,所以就需要計算出兩個日期間的實際工作日天數(shù)。本文用Python+SeaTable實現(xiàn)這一需求,需要的可以參考一下2022-07-07Pycharm遠(yuǎn)程連接服務(wù)器并運行與調(diào)試
本篇文章介紹一下 Pycharm 如何配置遠(yuǎn)程連接信息,使其能夠在本地使用服務(wù)器上的GPU等硬件資源,并在本地完成代碼的運行與調(diào)試,感興趣的可以了解一下2021-08-08Python實現(xiàn)單鏈表中元素的反轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Python實現(xiàn)單鏈表中元素的反轉(zhuǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05