20240328爬虫代码记录
def get_com(request): print(requests) data = request.POST body_list = data['body_list'].split(',') Cookie = "SESSION=ZThmN2JiZjAtZjYyZC00NmY5LWI2ZWItMjM0ZmE5NjgwYjgz" # 定义请求头 headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36", "Cookie": Cookie, "Referer": "http://eip.gmcc.net/poa/portalwork/workbench.do", "Host": "eip.gmcc.net", "Origin": "http://eip.gmcc.net", "Content-Type": "application/json;", } params = { "body": "kCudJ+vuZFWlavjw63JiCEHn00Aqgx12A8chqCL5wsw3sIvEwL6AV/u5tcsnutMKC7nLbBlgKbcDgzRdrYFhaf+0cApuGTSBUdJxyFocAvoGh9dUK6Zu+kX7nj7/UihJlyWuAKZY4smMwd7na5Ybfg==", } checkphone_url = "http://eip.gmcc.net/poa/addressBook/queryUsersPageList.do" df = pd.DataFrame() row_index = 0 page_index = 0 for body in body_list: print(page_index) page_index+=1 params['body'] = body response = requests.post(checkphone_url, headers=headers, params=params) r_data = response.json() data_list = r_data['resultData']['list'] for row in data_list: df.loc[row_index, 'fullName'] = row['fullName'] df.loc[row_index, 'employee'] = row['employee'] df.loc[row_index, 'company'] = row['company'] df.loc[row_index, 'branch'] = row['branch'] df.loc[row_index, 'department'] = row['department'] df.loc[row_index, 'userGrade'] = row['userGrade'] df.loc[row_index, 'title'] = row['title'] df.loc[row_index, 'telePhone'] = row['telePhone'] df.loc[row_index, 'email'] = row['email'] row_index += 1 df.to_excel("通讯录.xlsx") return JsonResponse({"res": "成功"})
随便用