首頁  >  文章  >  後端開發  >  用python3進行模擬登入v2ex

用python3進行模擬登入v2ex

巴扎黑
巴扎黑原創
2017-07-21 13:27:581497瀏覽

閒的無聊。 。 。

網路上一堆,正好練手(主要是新手)

# coding=utf-8
import requests  
from bs4 import BeautifulSoup

headers = {
   'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87/537.36', 1/56.0.2924.87 ://www.php.cn',  
   'referer': 'https://www.php.cn/signin',  
   'host': 'www.php.cn',  
}
s = requests.Session()  
r = s.get('https://www.php.cn/signin', headers=headers)
soup = BeautifulSoup(r.content, "html .parser")

#取得登入資料

once = soup.find('input', {'name': 'once'})['value']
name = soup.find ('input', {'type': 'text', 'class': 'sl'})['name']
password = soup.find('input', {'type': 'password', 'class': 'sl'})['name']
login_data = {
name : 'xxx',
password : 'xxx',
'once' : once,
'next' : '/'
}

#登入

s.post('https://www.php.cn/signin', login_data, headers=headers)

以上是用python3進行模擬登入v2ex的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn