爬蟲-某網站的模擬登錄

import requests
from datetime import datetime
import json

class new_gw():
    login_url = 'https://www.xxxxxxxxr.cn/login'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
                      '(KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
    }
    data = {
        'username':'1342691',
        'password':123456
    }
    session = requests.session()
    response = session.post(url=login_url, headers=headers, data=data)
    
    print(response)
    # 官網-用戶詳情返回的數據
    response_text = session.get(url='https://https://www.xxxxxxxxr.cn/loginr.cn/xxxxst?otype=college', headers=headers)
    print(response_text.json())
    #  官網-首頁返回的json數據  search爲搜索的參數
    response_text = session.get(url='xxxxxxxxx?search=紐約大學', headers=headers)
    print(response_text.json())


if __name__ == '__main__':
    start_time = datetime.now()
    new_gw()
    end_time = datetime.now()
    print('執行時間{time}'.format(time=end_time-start_time))

返回數據

返回的是一個json的案例
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章