python 爬取學(xué)信網(wǎng)登錄頁面的例子
我們以學(xué)信網(wǎng)為例爬取個(gè)人信息
**如果看不清楚
按照以下步驟:**
1.火狐為例 打開需要登錄的網(wǎng)頁–> F12 開發(fā)者模式 (鼠標(biāo)右擊,點(diǎn)擊檢查元素)–點(diǎn)擊網(wǎng)絡(luò) –>需要登錄的頁面登錄下–> 點(diǎn)擊網(wǎng)絡(luò)找到 一個(gè)POST提交的鏈接點(diǎn)擊–>找到post(注意該post中信息就是我們提交時(shí)需要構(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)登錄頁面的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python+SeaTable實(shí)現(xiàn)計(jì)算兩個(gè)日期間的工作日天數(shù)
在實(shí)際的項(xiàng)目管理、任務(wù)管理、工作計(jì)劃等場(chǎng)景中,某些時(shí)間段會(huì)涉及雙休日、法定節(jié)假日,甚至還有公司自定義的工作時(shí)間安排,所以就需要計(jì)算出兩個(gè)日期間的實(shí)際工作日天數(shù)。本文用Python+SeaTable實(shí)現(xiàn)這一需求,需要的可以參考一下2022-07-07
Pycharm遠(yuǎn)程連接服務(wù)器并運(yùn)行與調(diào)試
本篇文章介紹一下 Pycharm 如何配置遠(yuǎn)程連接信息,使其能夠在本地使用服務(wù)器上的GPU等硬件資源,并在本地完成代碼的運(yùn)行與調(diào)試,感興趣的可以了解一下2021-08-08
Python實(shí)現(xiàn)單鏈表中元素的反轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)單鏈表中元素的反轉(zhuǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Python OpenCV處理圖像之圖像像素點(diǎn)操作
這篇文章主要為大家詳細(xì)介紹了Python OpenCV處理圖像之圖像像素點(diǎn)操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07
Python 26進(jìn)制計(jì)算實(shí)現(xiàn)方法
這篇文章主要介紹了Python 26進(jìn)制計(jì)算實(shí)現(xiàn)方法,涉及Python字符串與數(shù)值計(jì)算的相關(guān)操作技巧,需要的朋友可以參考下2015-05-05

