#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from urllib import request
import json
from datetime import datetime, timedelta
import time
def get_data():
url = 'https://search.51job.com/list/070200,000000,0000,00,9,99,java%25E5%25BC%2580%25E5%258F%2591,2,1.html'
headers = {
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
}
req = request.Request(url, headers=headers)
response = request.urlopen(req)
print('===============', response.getcode(), type(response))
if response.getcode() == 200:
# 字节码
data = response.read()
print(type(data))
# 字节码转字符串
data = data.decode('utf-8')
print(type(data))
# print(data)
with open('index.html', mode='w', encoding='utf-8') as f:
f.write(data)
if __name__ == '__main__':
get_data()