簡單的模擬登錄Wap版新浪微博


環境:Ubuntu 16.04

python版本3.5+

import requests, lxml
from bs4 import BeautifulSoup
from io import BytesIO
from PIL import Image


class SimulationLogging:
    # 構造data
    def structure_data(self):
        data = {
            'remember': 'on',
            'backURL': 'http://weibo.cn/1786213845/fans?vt=4',
            'backTitle': '微博',
            'tryCount': '',
            'submit': '登錄'
        }
        url = 'http://weibo.cn/1786213845/fans?vt=4'
        i = requests.get(url).text
        r = BeautifulSoup(i, "lxml")
        url_2 = 'http://login.weibo.cn/login/'
        url_login = url_2 + str(r.find('form', method="post").get('action'))
        password_name = r.find('input', type="password").get('name')
        username = input('請輸入用戶名:')
        data['mobile'] = username
        password = input('請輸入密碼')
        data[password_name] = password
        vks = r.find_all('input')
        data['vk'] = vks[7].get('value')
        data['capId'] = vks[8].get('value')
        img = r.find('img', alt="請打開圖片顯示").get('src')
        file = BytesIO(requests.get(img).content)
        img = Image.open(file)
        img.show()
        code = input('請輸入顯示的驗證碼(不分大小寫)')
        data['code'] = code
        img.close()
        self.get_content(url_login, data)
        # 獲取網頁內容

    def get_content(self, url_login, data):
        request = requests.post(url_login, data=data).text
        r = BeautifulSoup(request, "lxml")
        print(r)


if __name__ == '__main__':
    test = SimulationLogging()
    test.structure_data()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM