1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<div class="question">
<span>1169608</span>
<span class="operator">+</span>
<span>1395490</span>
<span class="equals">=</span>
<span style="color: #ff6b6b;">?</span>
</div>

<form id="answerForm" action="answer.php" method="POST">
<input type="hidden" name="token" value="0">
<div class="input-group">
<input type="text" name="answer" id="answerInput" placeholder="输入你的答案" autocomplete="off" autofocus>
</div>
<button type="submit" class="submit-btn">提交</button>
</form>

看接口写脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

import re

import requests
from bs4 import BeautifulSoup

BASE_URL = "http://8.154.22.32:20005/"

s = requests.Session()

for i in range(100):
r = s.get(BASE_URL)
r.raise_for_status()

soup = BeautifulSoup(r.text, "html.parser")

token = soup.find("input", {"name": "token"})["value"]

q = soup.select_one(".question").get_text(" ", strip=True)
nums = list(map(int, re.findall(r"\d+", q)))

if "+" in q:
ans = nums[0] + nums[1]
elif "-" in q:
ans = nums[0] - nums[1]
elif "*" in q or "×" in q:
ans = nums[0] * nums[1]
elif "/" in q or "÷" in q:
ans = nums[0] // nums[1]
else:
raise Exception(f"未知运算: {q}")

res = s.post(BASE_URL + "answer.php", data={"token": token, "answer": str(ans)})

print(f"[{i + 1}/100] {q} {ans}")

print(res.text)