簡體   English   中英

python selenium chrome,如何設置瀏覽器的請求主體

[英]python selenium chrome,How to set up the browser's request body

我正在網上搜索很長時間。 但是沒用。 請幫助或嘗試給出一些想法來實現這一目標。

問題的源頭是第一次,手動滑動輸入驗證碼后,網站輸入后將返回ACCESS_TOKEN,令牌將在1小時后過期,我在一個小時內還是刷新頁面,快一個小時后才刷新頁面,我將返回一個新令牌,即我將登錄一次,后面只需刷新頁面即可。

但是現在出現了一個問題,Chrome將以某種方式關閉,因此在判斷瀏覽器處於關閉狀態時,我需要重新啟動瀏覽器,然后按以下方式發布數據。

發布標題是這樣的:

POST https://www.test.com/rest.php HTTP/1.1
Host: api.test.com
Connection: keep-alive
Content-Length: 216
Origin: https://api.test.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
Content-type: application/x-www-form-urlencoded
Accept: */*
Referer: https://api.test.com/nspcross.html
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: CASLOGIN=true; CASLOGINSITE=1; LOGINACCSITE=1

nsp_svc=AppPromote.Developer.getRole&access_token=CFpS9d%2FDFoxQvOiM%2B%2F3j1iFce0dYDYQR0qq7TfAVUG5e%2FGhgBx2jHL6p8M02y09V%2FEHQpwemI7V1ACD32ERFD45678FGTHDBW3EI6iX4%3D&nsp_fmt=JSON&nsp_ts=18547841246
import os
import re
import psutil
import seleniumrequests
#判斷瀏覽器狀態
def handle_brower_statue():
    while True:
        brower_list = []
        pids = psutil.pids()
        pid_name_search = re.compile(r'chrome')
        for pid in pids:
            p = psutil.Process(pid)
            pid_name_chrome = re.search(pid_name_search, p.name())
            if pid_name_chrome == None:
                pass
            else:
                brower_list.append(pid)
        print len(brower_list)
        if len(brower_list) < 8:
            for kill_pid in brower_list:
                os.system("kill -9 %s" % kill_pid)
            access_token = read_access_token()
            new_data = {
                "nsp_svc":"AppPromote.Developer.getRole",
                "access_token":access_token,
                "nsp_fmt":"JSON",
                "nsp_ts":setting.nsp_ts,
            }
            new_driver = seleniumrequests.Chrome()
            time.sleep(2)
            response = new_driver.request('POST','https://api.xxxx.com/rest.php',data=new_data)
            print response.text

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM