Base64编码作业
目标网站:https://www.zlkt.net/training/jscrack/base6403?CourseId=1&BarId=10
import requests
from ODtools import headers
from lxml.etree import HTML
base_text = '7DusnzUrVTcKo8Q21mylZF4SMBWdfaEx+/5Xghj69iIwtGeHAPvNOpCY0LRJqbk3='
headers['cookie'] = 'zhiliao_website=73a6321cfca4408e5ce76e3d6907ea62; _xsrf=eU0wTkNXVzdzbmswN0QyUjc3TTBZQnJJTm1mV2c1dEw=|1617589636958461687|38345b77d589d5bef01934a8ecff8bc712e6fe70'
resposne = requests.get('https://www.zlkt.net/training/jscrack/base6403?CourseId=1&BarId=10', headers=headers)
doc = HTML(text=resposne.content.decode())
text = doc.xpath('//div[@id="table"]/text()')[0]
n = 0
temp = ''
while n < len(text):
s1 = base_text.index(text[n])
n += 1
s2 = base_text.index(text[n])
n += 1
s3 = base_text.index(text[n])
n += 1
s4 = base_text.index(text[n])
n += 1
p1 = s1 << 2 | s2 >> 4
p2 = (s2 & 15) << 4 | s3 >> 2
p3 = (s3 & 3) << 6 | s4
temp += chr(p1)
if s3 != 64:
temp += chr(p2)
if s4 != 64:
temp += chr(p3)
new_temp = ''
r1 = 0
r2 = 0
r3 = 0
r4 = 0
while r1 < len(temp):
r2 = ord(temp[r1])
if r2 < 128:
new_temp += chr(r2)
r1 += 1
elif 191 < r2 < 224:
r3 = ord(temp[r1+1])
new_temp += chr((r2 & 31) << 6 | r3 & 63)
r1 += 2
else:
r3 = ord(temp[r1 + 1])
r4 = ord(temp[r1 + 2])
new_temp += chr((r2 & 15) << 12 | (r3 & 63) << 6 | r4 & 63)
r1 += 3
print(new_temp)
输出
<table border='1'>
<thead>
<tr>
<th>航空</th>
<th>时间</th>
<th>路线</th>
<th>价格</th>
</tr>
</thead>
<tbody>
<tr>
<td>中国国航CA1350</td>
<td>08:20-10:40</td>
<td>长沙黄花国际机场-首都国际机场T3</td>
<td>1900</td>
</tr>
<tr>
<td>中国国航CA1344</td>
<td>11:15-13:35</td>
<td>长沙黄花国际机场-首都国际机场T3</td>
<td>1600</td>
</tr>
<tr>
<td>中国国航CA1374</td>
<td>17:20-19:40</td>
<td>长沙黄花国际机场-首都国际机场T3</td>
<td>1500</td>
</tr>
<tr>
<td>南方航空CZ3123</td>
<td>07:30-09:45</td>
<td>长沙黄花国际机场-首都国际机场T3</td>
<td>1620</td>
</tr>
</tbody>
</table>