日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

利用python爬虫技术本福特_Python爬虫技术(一)--模拟登陆

發布時間:2024/9/30 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 利用python爬虫技术本福特_Python爬虫技术(一)--模拟登陆 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

好了,最后上完整代碼,當當當當~

# -*- coding: utf-8 -*-

import requests

import sys

import urllib2

import re

if __name__ == "__main__":

## 這段代碼是用于解決中文報錯的問題

reload(sys)

sys.setdefaultencoding("utf8")

posturl = "http://ids.chd.edu.cn/authserver/login?service=http://portal.chd.edu.cn/index.portal"

#保存cookies,不保存cookie很危險,登陸成功后不保存cookie服務器將不知道你已經登錄

#或者說服務器不知道你是你,就導致獲得頁面失敗

s = requests.session()

circle = s.get(posturl).text

#查找lt字符串

#長大信息門戶中有幾個隱藏表單項,lt表單項為一個隨機字符串

#其余幾個均為固定字符串

#所以我們必須先得到lt字符串

ltString = '

ltAnswer = re.findall(ltString, circle)

lt = ltAnswer[0].replace('

#構造頭部信息

head = {

'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

'Accept-Encoding' : 'gzip,deflate',

'Accept-Language' : 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',

'Host' : 'ids.chd.edu.cn',

'Connection' : 'keep-alive',

#反爬蟲技術,這個說明我們是從這個網頁進入的

'Referer' : 'http://ids.chd.edu.cn/authserver/login?service=http://portal.chd.edu.cn/index.portal',

'Upgrade-Insecure-Requests' : '1',

#偽裝瀏覽器

'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0'

}

#構造Post數據

postData = {'_eventId' : "submit",

'btn1' : "",

'dllt' : "userNamePasswordLogin",

'execution': "e1s1",

'lt' : lt,

'password' : "*******",

'rmShown' : "1",

'username' : "123456789",

}

loginhtml = s.post(posturl,data=postData,headers=head)

url2 = 'http://portal.chd.edu.cn'

head2 = {

'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0',

'Referer' : 'http://ids.chd.edu.cn/authserver/login?service=http://portal.chd.edu.cn/index.portal'}

scorehtml = s.get(url2,headers=head2)

print scorehtml.text.decode('gbk','ignore')

好了,本次實驗到此結束,歡迎一起學習更多知識!

總結

以上是生活随笔為你收集整理的利用python爬虫技术本福特_Python爬虫技术(一)--模拟登陆的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。