python填寫金資料

2022-08-19 08:51:07 字數 3451 閱讀 6170

1

'''2

將 main 中的改為真 url

3將 setd_data中 改為確切資料

4資料自行參考post

5結果判斷基於響應中是否包含「謝謝參與」字樣

6'''

7import

requests

8importre9

import

time

10import

random

11import

datetime

1213

class

jinshujv:

14def

__init__

(self,url):

15 self.url =url

16 self.post_url =url

17 self.header =none

18 self.cookie =none

19 self.data =none

2021

defset_header(self):

22"""

23隨機生成ip,設定x-forwarded-for

24:return:

25"""

26 ip = '

{}.{}.{}.{}

'.format(112, random.randint(64, 68), random.randint(0, 255), random.randint(0, 255))

27 self.header =

3435

defget_response(self):

36"""

37訪問問卷網頁,獲取網頁**

38:return: get請求返回的response

39"""

40 response = requests.get(url=self.url, headers=self.header)

41 self.cookie =response.cookies

42return

response

4344

defget_authenticity_token(self,response):

45 authenticity_token=re.search(r'

(?<=name="csrf-token" content=")\s+(==>?)

',response.text)

46return

authenticity_token.group()

4748

defset_data(self):

49 response =self.get_response()

50 authenticity_token =self.get_authenticity_token(response)

51 now=str(datetime.date.today())

52def

temperature():

53 high=round(random.uniform(36.5,37.0),1)

54 low=round(high-round(random.uniform(0.3,0.5),1),1)

55 high=str(high)

56 low=str(low)

57return

[high,low]

5859 data=

60 data.update()

61 data.update()

62 data.update()

63 data.update()

64 data.update("})

65 data.update()

66 data.update()

67 data.update()

68 data.update()

69 data.update()

70 data.update()

71 data.update()

72 data.update("})

73 data.update("})

74 data.update("})

75 data.update()

76 data.update()

77 data.update()

78 data.update()

79 data.update()

80 data.update()

81 data.update()

82 data.update()

83 data.update()

84 data.update()

85 data.update()

86 self.data=data

8788

defpost_data(self):

89"""

90傳送資料給伺服器

91:return: 伺服器返回的結果

92"""

93self.set_data()

94 response = requests.post(url=self.post_url, data=self.data, headers=self.header, cookies=self.cookie)

95return

response

9697

defrun(self):

98self.set_header()

99 result =self.post_data()

100#

print(result.content.decode())

101if

"謝謝參與"in

result.content.decode():

102print("

success")

103else

:104

print("

fail")

105106

if__name__ == "

__main__":

107 j=jinshujv()

108 j.run()

參考:

輸入資料,填寫其他資料

在網上經常會看到一些輸入某項資料就可以把其他關聯的資料顯示出來,具體怎麼實現這個功能呢,下面我來演示一下 這個呢,就是要實現的效果,就是輸入前面的編號,就可以把後面的名稱顯示出來,來看下它的css 這個就是它的 再來看下它的方法 這裡通過查詢編號,來獲取名稱和id,然後就是呼叫這個方法 這裡通過na...

Python使用Selenium填寫問卷調查表單

2 from selenium import webdriver from selenium.webdriver.common.by import by from selenium.webdriver.support.ui import webdriverwait from selenium.web...

pycharm執行python時,填寫引數的方法

1 按快捷鍵 alt shift f10調出執行視窗,之後選擇edit configurations或者按0 2 輸入引數,點選執行程式設計客棧 以上這篇pycharm執行python時,填寫引數程式設計客棧的方法就是小編分享給大ctnmzf家的全部內www.cppcns.com容了,希望能給大家乙...