话不多说,直接上代码
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import time
import json
import math
import random
import requests
import pandas as pd
class GDSK:
"""广东省考报名人数实时爬取"""
def __init__(self):
self.url = 'https://ggfw.gdhrss.gov.cn/gwyks/exam/details/spQuery.do'
self.headers = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': 'xxxxxxxxxxx', # 爬取数据前,需要登录账号后,复制新的cookie过来
'User-Agent': 'Mozilla/5.0xxx', # 浏览器ua,需要更新为你的浏览器
}
def get_one_page_to_txt(self, num, rows, city, path):
"""
爬取一页的信息,并保存为txt文件
num: 需要爬取的页码
rows: 每页记录数
city: 需要爬取的城市
path: txt文件存储的路径
"""
# 不同城市,编码不同
if city == '省直':