# !/usr/bin/env python # -*- coding:utf-8 -*- """ # File : XXXX.py # Time :2023/8/18 11:38 # Author :lrtao2010 # version :python 3.10.1 # Description:获取XXXX个股前十大股东 """ #导入模块 import requests #下载网页 import bs4 #beautifulsoup4 解析网页 import time import random #自定义请求头 my_headers = { 'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Host': 'XXXX.XXXX.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' } #生成股票代码列表 my_code_list = [] with open("./shuju/XXXX.txt",encoding='utf-8')as f: for i in f.readlines(): my_code_list.append(i.strip()) #print(my_code_list) #主程序 for my_list in my_code_list: print(my_list) page_obj = requests.get(f"http://XXXX.XXXX.com//?XXXX?XXXX={my_list}",headers=my_headers) #print(page_obj.text) bs4_obj = bs4.BeautifulSoup(page_obj.text,"lxml") shareholder_eles = bs4_obj.find_all("tr",attrs={"height":"25"}) shareholder_num = 1 for eles in shareholder_eles: if shareholder_num <= 10: shareholder = eles.find("a", attrs={"class": "anews2"}) if shareholder != None: with open("./shuju/shareholder.txt", 'a+',encoding='utf-8')as s_f: s_f.writelines(f"{my_list}" + " " + shareholder.text + "\n") shareholder_num += 1 time.sleep(random.randint(1,2))
标签:02,code,XXXX,image,list,获取,obj,my From: https://www.cnblogs.com/lrtao2010/p/18041402