我們以學(xué)信網(wǎng)為例爬取個(gè)人信息
**如果看不清楚
按照以下步驟:**
1.火狐為例 打開需要登錄的網(wǎng)頁?C> F12 開發(fā)者模式 (鼠標(biāo)右擊,點(diǎn)擊檢查元素)?C點(diǎn)擊網(wǎng)絡(luò) ?C>需要登錄的頁面登錄下?C> 點(diǎn)擊網(wǎng)絡(luò)找到 一個(gè)POST提交的鏈接點(diǎn)擊?C>找到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è)參考,也希望大家多多支持腳本之家。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
