import
requests
import
re
from
PIL
import
Image
import
time
import
hashlib
from
fake_useragent
import
UserAgent
imgUrl
=
re.
compile
(
'background-image: url\((.*?)\)'
)
positions
=
re.
compile
(
"class='gt_cut_fullbg_slice' style='background-position:(.*?)px (.*?)px;'>"
)
ua
=
UserAgent()
url
=
'https://authcode.51.com/authcode/slidecode'
headers
=
{
'User-Agent'
: ua.random
}
params
=
{
'callback'
:
'jQuery11110024185931707424446_1648388960494'
,
'from'
:
'passport'
,
'_'
:
'1648388960512'
}
html
=
requests.get(url,headers
=
headers,params
=
params)
print
(
'html.text->'
,html.text)
imgurls
=
imgUrl.findall(html.text)
for
us
in
imgurls:
if
'big'
in
us:
bigImg
=
'https:'
+
us.replace(
"\/"
,
'/'
).replace(
'\\"'
,'')
print
(
'bigImg->'
,bigImg)
pos_lists
=
[]
positions
=
positions.findall(html.text)
for
ps
in
positions:
x
=
int
(ps[
0
])
y
=
int
(ps[
1
])
pos_lists.append({
"x"
:x,
"y"
:y})
bg_img
=
requests.get(bigImg).content
with
open
(
'51原图.png'
,
'wb'
)as f:
f.write(bg_img)
im
=
Image.
open
(
'51原图.png'
)
new_pos
=
[]
for
pos
in
pos_lists:
if
pos[
'y'
]
=
=
-
75
:
new_pos.append(im.crop((
abs
(pos[
'x'
]),
75
,
abs
(pos[
'x'
])
+
13
,
100
)))
if
pos[
'y'
]
=
=
-
50
:
new_pos.append(im.crop((
abs
(pos[
'x'
]),
50
,
abs
(pos[
'x'
])
+
13
,
75
)))
if
pos[
'y'
]
=
=
-
25
:
new_pos.append(im.crop((
abs
(pos[
'x'
]),
25
,
abs
(pos[
'x'
])
+
13
,
50
)))
if
pos[
'y'
]
=
=
0
:
new_pos.append(im.crop((
abs
(pos[
'x'
]),
0
,
abs
(pos[
'x'
])
+
13
,
25
)))
new_im
=
Image.new(
'RGB'
, (
260
,
100
))
x_offset
=
0
y_offset
=
0
for
im
in
new_pos:
if
(x_offset
=
=
260
):
x_offset
=
0
y_offset
+
=
25
new_im.paste(im, (x_offset, y_offset))
x_offset
+
=
13
print
(
'ok'
,
'{}.png'
.
format
(
'resul'
))
new_im.save(
'./{}.png'
.
format
(
'51原图还原后'
))
my_time
=
int
(time.time()
*
1000
)
times
=
re.
compile
(
'<inpu.*?times.*?value=(.*?)>'
)
times
=
times.findall(html.text)[
0
].replace(
'\\"'
,'')
challenge
=
re.
compile
(
'<inpu.*?challenge.*?value=(.*?)>'
)
challenge
=
challenge.findall(html.text)[
0
].replace(
'\\"'
,'')
point
=
'68'
re_url
=
'https://authcode.51.com/authcode/yz2'
params1
=
{
'callback'
: f
'jQuery111104273542489406337_'
+
str
(my_time),
'point'
: point,
'times'
: times,
'challenge'
: challenge,
'token'
: hashlib.md5((challenge
+
times
+
point).encode(
'utf8'
)).hexdigest(),
'from'
:
'passport'
,
'divpre'
:'',
'_'
:
str
(my_time)
}
re_html
=
requests.get(re_url,params
=
params1)
print
(re_html.text)