爬取东方证券上的券商数据

通过东方证券WEB端逆向其接口,以爬取37个AB股数据为例

代码写的比较混乱:

from httpx import Client
from json import loads
from alive_progress import alive_it

client = Client(
    headers={
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50"
    }
)


def parse_broker(broker_id):
    url = f"http://emweb.securities.eastmoney.com/PC_HSF10/NewFinanceAnalysis/ZYZBAjaxNew?type=1&code={broker_id}"
    res = client.get(url)
    try:
        data: list = res.json()["data"]
    except KeyError:
        print(broker_id)
        return

    total = [i["TOTALOPERATEREVE"] for i in data]
    profit = [i["PARENTNETPROFIT"] for i in data]

    return total, profit


def get_brokers():
    url = "https://search-api-web.eastmoney.com/search/jsonp?cb=jQuery35105205651282387875_1677270053469&param=%7B%22uid%22%3A%22%22%2C%22keyword%22%3A%22%E8%AF%81%E5%88%B8%22%2C%22type%22%3A%5B%22codetableLabelWeb%22%5D%2C%22client%22%3A%22web%22%2C%22clientType%22%3A%22wap%22%2C%22clientVersion%22%3A%22curr%22%2C%22param%22%3A%7B%22codetableLabelWeb%22%3A%7B%22pageIndex%22%3A1%2C%22pageSize%22%3A50%2C%22preTag%22%3A%22%22%2C%22postTag%22%3A%22%22%2C%22isHighlight%22%3Afalse%2C%22label%22%3A%22AB_STOCK%22%7D%7D%7D&_=1677270053474"
    res = client.get(url)
    text = res.text
    json = text[text.index("(") + 1: text.index(")")]
    data = loads(json)
    ids = [i["securityType"][:2] + i["code"] for i in data["result"]["codetableLabelWeb"]["labelList"][0]["quoteList"]]
    return ids


if __name__ == '__main__':
    all_data = {i: parse_broker(i) for i in alive_it(get_brokers())}

结果为:

{
  "SH600030": [
    [
      76523716526.93,
      54382730241.56,
      43139697642.01,
      37220708075.49,
      43291634080.53,
      38001695917.06,
      56013436032.55,
      29197531133.19,
      16115272156.7
    ],
    [
      23099624927.77,
      14902324215.75,
      12228609723.82,
      9389895989.94,
      11433264545.6,
      10365168588.41,
      19799793374.33,
      11337193825.46,
      5243916979.11
    ]
  ],
  "SH600109": [
    [
      7126630308.69,
      6062801499.95,
      4349514734,
      3766119304.82,
      4390587320.59,
      4671462425.22,
      6748452672.79,
      2721722488.96,
      1546260843.9
    ],
    [
      2317318717,
      1862640224.66,
      1298539701.33,
      1010492527.44,
      1201432521.06,
      1298730528.61,
      2359776226.13,
      836489632.37,
      315915955.64
    ]
  ],
  "SH600369": [
    [
      3096080385.1,
      3169571453.97,
      3488837437.18,
      2744154393.47,
      3060764762.1,
      3631762015.75,
      8496799180.16,
      3674829197.88,
      1964126453.35
    ],
    [
      1038152895.95,
      1091487407.23,
      1042001454.67,
      226842591.87,
      668800161.74,
      917572729,
      3554650541.89,
      1339048940.41,
      630328806.7
    ]
  ],
  "SH600837": [
    [
      43205467448.92,
      38219828310.55,
      34860320039.44,
      23765014627.26,
      28221667163.35,
      28011014594.51,
      38086267720.37,
      17978474435.1,
      10454954029.51
    ],
    [
      12826517065.48,
      10875396346.26,
      9523247834.58,
      5211093198.87,
      8618423293.06,
      8043334519.3,
      15838850897.61,
      7710623597.6,
      4035024048.18
    ]
  ],
  "SH600906": [
    [
      2524296711.14,
      2049789593.71,
      1813260306.57,
      1460659256.36,
      1469446884.96,
      1826594490.25,
      3901471990.05,
      2019138077.72,
      1061354574.54
    ],
    [
      680476070.18,
      531912511.18,
      609173507,
      73632352.15,
      296796161.76,
      656518792.32,
      2044799148.99,
      832084944.53,
      231616429.41
    ]
  ],
  "SH600909": [
    [
      3483420429.82,
      3356521373.89,
      3231605381.54,
      1761325423.29,
      1917696780.54,
      1733047755.13,
      3816204907.49,
      1689616580.33,
      941343121.09
    ],
    [
      1424067013.48,
      1267903291.32,
      1108359114.76,
      553744956.32,
      649726827.62,
      602013378.58,
      1865072011.2,
      686113287.1,
      187193507.17
    ]
  ],
  "SH600918": [
    [
      13149669222.3,
      10352224019.84,
      9708987193.91,
      7025218940.45,
      8168926941.65,
      8347371893.3,
      15045289807.52,
      5874417405.85,
      4081226500
    ],
    [
      3200009354.36,
      2525298270.86,
      2249463067.12,
      1009145069.71,
      1795153414.05,
      2451977469.41,
      6062485984.47,
      1873533391.99,
      869628500
    ]
  ],
  "SH600958": [
    [
      24370394956.88,
      23133946765.29,
      19052097313.75,
      10303490892.44,
      10531511324.13,
      6876188934.65,
      15434705061.27,
      5499603011.02,
      3243936742.44
    ],
    [
      5371496261.61,
      2722988518.72,
      2435079764.1,
      1231013208.91,
      3553626384.73,
      2313974857.75,
      7325224517.53,
      2341671183.75,
      1007421947.97
    ]
  ],
  "SH600999": [
    [
      29428896087.24,
      24277670240.59,
      18708369944.73,
      11321611555.03,
      13353213641.86,
      11695453558.82,
      25291794057.95,
      11002468274.67,
      6089160550.68
    ],
    [
      11645065137.15,
      9491638796.98,
      7282380829.33,
      4424985940.97,
      5785955137.26,
      5403450595.57,
      10908748759.12,
      3850672721.41,
      2232090360.47
    ]
  ],
  "SH601059": [
    [
      3803275799.41,
      3162361349.94,
      2222965979.52,
      1658818758.06,
      1762887403.74,
      2242660878.57,
      5234510738.09,
      3097204862.03,
      1661336185.25
    ],
    [
      1171719584.88,
      819688097.83,
      210067991.93,
      69957389.3,
      172176509.45,
      435328833.94,
      2082044520.29,
      913783708.6,
      324659377.97
    ]
  ],
  "SH601108": [
    [
      6407610366.67,
      6528040616.43,
      4952243604.81,
      3167998370.32,
      4016866764.74,
      4255580080.75,
      10241340331.37,
      4502280609.9,
      2259136500
    ],
    [
      2566175327.88,
      2291596618.3,
      1873062523.33,
      818836066.51,
      1503931618.18,
      1785885436.51,
      3075405936.63,
      855682830.24,
      326433600
    ]
  ],
  "SH601136": [
    [
      2113493479.32,
      1657983958.5,
      1339618763.5,
      815247500,
      930567402.63,
      1102020020.79,
      1633423521.59,
      779189943.03,
      436445716.61
    ],
    [
      858599660.48,
      610616529.86,
      433970302.57,
      174816400,
      315419298.15,
      422830229.13,
      716586155.66,
      273283091.03,
      145426328.76
    ]
  ],
  "SH601162": [
    [
      4405719313.76,
      4359629544.39,
      3846100730.48,
      3277404101.33,
      2986161700.23,
      3097919718.74,
      3213163664.24,
      1112169600.14,
      668629269.05
    ],
    [
      586354789.34,
      454871365.71,
      307767555.05,
      302851495.02,
      410130726.93,
      671567746.98,
      937586413.65,
      207746164.65,
      100802284.59
    ]
  ],
  "SH601198": [
    [
      5375748343.46,
      5687210822.32,
      4474704697.42,
      3314496768.38,
      3633172002.15,
      3573200156.02,
      5363008065.25,
      2597774148.38,
      2033866487.14
    ],
    [
      1652243606.93,
      1539672462.5,
      1220698859.37,
      1008047034.4,
      1309249598.89,
      1352929314.59,
      2044690319.02,
      1040597699.34,
      668493992.39
    ]
  ],
  "SH601236": [
    [
      6733758206.26,
      5585163238.85,
      2065728507.8,
      1201433406.34,
      1114215786.02,
      975655348.13,
      1974885800,
      1214603799.66,
      764936044.28
    ],
    [
      1576229463.11,
      1413122029.42,
      837541304.24,
      386464525.52,
      363082587.7,
      332827972,
      1042533800,
      475496800.72,
      218206973.48
    ]
  ],
  "SH601375": [
    [
      4420848497.96,
      3103301696.87,
      2372526991.25,
      1649661561.68,
      2147620089.37,
      2008852561.18,
      4004355251.9,
      1808216779.12,
      1165234691.42
    ],
    [
      513210337.25,
      104302038.78,
      58222745.44,
      65787558.62,
      441982592.67,
      718646243.11,
      1405500406.97,
      562290151.78,
      252934345.88
    ]
  ],
  "SH601377": [
    [
      18972168754.91,
      17579687208.8,
      14249535861.49,
      6499373437.14,
      8820388610.14,
      7588604128.9,
      11540612657.75,
      5609064896.32,
      3099526553.02
    ],
    [
      4743070343.36,
      4003314315.75,
      1762537169.01,
      135348071.2,
      2284896126.79,
      2046321431.54,
      4167150649.35,
      1781589789.14,
      669769790.41
    ]
  ],
  "SH601456": [
    [
      2966631400.54,
      1876340313.32,
      1619382372.77,
      989719000,
      1262535000,
      1836463830.87,
      3079072000,
      1668332000,
      1000977188.45
    ],
    [
      888639753.44,
      587871418.22,
      521344151.14,
      50588000,
      361492000,
      610067590.12,
      1471438000,
      714955000,
      269761799.58
    ]
  ],
  "SH601555": [
    [
      9245491796.09,
      7356492441.1,
      5130373462.68,
      4161925425.29,
      4144240488.37,
      4645225993.82,
      6830161925.32,
      3240982527.87,
      1609668051.56
    ],
    [
      2391778941.16,
      1707245952.72,
      1037174921.82,
      358411175.29,
      788122751.35,
      1498288506.38,
      2708494901.88,
      1115452050.88,
      392166585.94
    ]
  ],
  "SH601688": [
    [
      37905443652.44,
      31444546120.28,
      24863012026.33,
      16108262271.57,
      21108534070.71,
      16925935043.92,
      26261939871.49,
      12062303844.09,
      7182298873.45
    ],
    [
      13346106674.68,
      10822496891,
      9001644018.52,
      5032737702.7,
      9276520447.68,
      6270611459.43,
      10696870875.92,
      4486276132.08,
      2219735131.23
    ]
  ],
  "SH601696": [
    [
      3333518749.21,
      3244172276.95,
      2907667567.52,
      2755098098.64,
      3067525846.44,
      2830493647.57,
      4947783600,
      2578182507.77,
      1290676825.47
    ],
    [
      961625314.57,
      883226868.37,
      798252971.86,
      704986351.02,
      1067129839.52,
      1065698139.13,
      2076890000,
      971638637.24,
      317617721.19
    ]
  ],
  "SH601788": [
    [
      16706575061.43,
      15866343425.84,
      10057362378.64,
      7712277101.82,
      9838147762.07,
      9164639102.5,
      16571087246.74,
      6601422929.86,
      4019623600.22
    ],
    [
      3484331817.14,
      2334078122.69,
      567944886.3,
      103322859.82,
      3016470221.54,
      3013019180.75,
      7646516077.13,
      2068307502.08,
      205836529.58
    ]
  ],
  "SH601878": [
    [
      16418113012.51,
      10636513832.41,
      5659478638.09,
      3694801371.08,
      4610873972.96,
      4594902987.59,
      6188903157.42,
      3226844444.08,
      1914709864.7
    ],
    [
      2195682763.42,
      1627166025.65,
      967557059.43,
      736957357.88,
      1063507778.68,
      1240892309.04,
      1834457999.29,
      750242395.43,
      403230607.26
    ]
  ],
  "SH601901": [
    [
      8621202071.85,
      7541809241.46,
      6594941981.46,
      5722593356.59,
      5961533467.39,
      7759738629.42,
      10914989706.62,
      4899699230.06,
      3453058407.18
    ],
    [
      1822282069.48,
      1096492270.9,
      1007595631.59,
      661365890.51,
      1452957913.42,
      2569336882.57,
      4064211991.64,
      1796097769.62,
      1112201945.05
    ]
  ],
  "SH601990": [
    [
      2741633842.89,
      2365296802.01,
      2201777265.63,
      1233927907.56,
      1388473496.81,
      1499611313.01,
      3000069643.36,
      1421284600,
      1014937100
    ],
    [
      977274472.85,
      809594147.08,
      709811700.41,
      231780216.69,
      410602756.36,
      493557293.51,
      1413026763.57,
      554444200,
      270930200
    ]
  ],
  "SZ000562": [
    [
      4118510581.83,
      3295868934.67,
      2353703631.17,
      3304715081.65,
      2919903998.54,
      1598468309.64,
      4435140101.43,
      743496322.22,
      -16990504.61
    ],
    [
      1227292426.2,
      867680007.09,
      645591117.7,
      1306379570.94,
      1151650925.85,
      541647861.52,
      2038300442.53,
      319354764.8,
      8222470.93
    ]
  ],
  "SZ000686": [
    [
      7477801881.89,
      6609613343.83,
      7968795586.85,
      6780105834.67,
      4934452308.92,
      4481994658.63,
      6745760224.97,
      3090984262.41,
      1767040160.7
    ],
    [
      1623994253.62,
      1333325683.24,
      1007080243.05,
      301352976.41,
      666946558.98,
      1314941187.9,
      2630058890.07,
      1060025355.59,
      480057377.95
    ]
  ],
  "SZ000728": [
    [
      6109751584.75,
      4528625617.88,
      3198808368.09,
      2537907348.38,
      3510702162.26,
      3375696421.01,
      5773382071.47,
      3486036145.6,
      1986134237.63
    ],
    [
      1909272808.14,
      1370096738.86,
      914361564.54,
      670370829.86,
      1203746140.88,
      1405404397.83,
      2784229089.24,
      1371744662.42,
      665338486.33
    ]
  ],
  "SZ000750": [
    [
      5170261555.13,
      4482015217.4,
      3560208077.82,
      2122602077.8,
      2658882600.15,
      3837926394.16,
      4959157199.17,
      2544981928.34,
      1818760812.32
    ],
    [
      764619396.32,
      725376273.77,
      487716781.47,
      73142828.57,
      375760243.11,
      1015511746.44,
      1792923492.86,
      690035776.56,
      308745854.57
    ]
  ],
  "SZ000776": [
    [
      34249988400.75,
      29153488259.04,
      22809882495.06,
      15270373023.59,
      21639300625.74,
      20714347818.02,
      33446639919.41,
      13394972903.67,
      8207540703.98
    ],
    [
      10854115527.4,
      10038134647.91,
      7538921643.02,
      4300126341.29,
      8595399060.76,
      8030106628.93,
      13201014064.72,
      5022567778.39,
      2812501034.32
    ]
  ],
  "SZ000783": [
    [
      8623165139.08,
      7784121537.42,
      7032892044.09,
      4369208710.77,
      5664107738.63,
      5857472375.4,
      8499643780.49,
      4548208653.84,
      3047682604.6
    ],
    [
      2409539473.91,
      2085377418.25,
      1665799971.58,
      257201958.69,
      1545112374.32,
      2206576040.14,
      3493365230.21,
      1705439086.94,
      1006554243.06
    ]
  ],
  "SZ002500": [
    [
      3993936447,
      3341972041,
      5102180737,
      6851136626,
      4392996390,
      2345649721,
      3838500324,
      1959188535,
      1321203859
    ],
    [
      803609850,
      750927346,
      510183708,
      221763054,
      408901264,
      467685616,
      1438829425,
      586294710,
      261755432
    ]
  ],
  "SZ002673": [
    [
      6751022663.82,
      5184163900.03,
      3680544587.4,
      2237341729.03,
      3169944961.76,
      3406329331.96,
      5640878792.18,
      1938470480.53,
      1132328589.81
    ],
    [
      1409991295.62,
      1117003407.01,
      610163902.78,
      200433916.35,
      752270907.74,
      1124621115.06,
      1972662987.16,
      663854622.42,
      275147001.3
    ]
  ],
  "SZ002736": [
    [
      23818037003.89,
      18784071244.98,
      14092914615.73,
      10030931922.89,
      11923610192.94,
      12746787440.92,
      29139131599.01,
      11792322619.69,
      6771922266.26
    ],
    [
      10114758795.89,
      6615739471.11,
      4910187206.37,
      3423396646.18,
      4574777573.93,
      4556152321.66,
      13949033996.79,
      4927564849.42,
      2101743057.35
    ]
  ],
  "SZ002926": [
    [
      5121995492.55,
      4682755761.6,
      3937424572.74,
      2545233363.8,
      2671626421.94,
      2710412262.05,
      6010918733.46,
      3168013932.48,
      1966121259.41
    ],
    [
      1632123985.51,
      1900327802.56,
      1431530824.81,
      845132348.07,
      1019124805.62,
      1666499975.29,
      2681090347,
      691276329.52,
      654193170.15
    ]
  ],
  "SZ002939": [
    [
      7756796088.56,
      6868697463.16,
      3899142493.53,
      2753299922.53,
      2957833928.02,
      3483558655.04,
      5012184673.07,
      2470089178.92,
      1550385558.88
    ],
    [
      1765610928.44,
      1501641468.72,
      992167143.29,
      585699848.79,
      889834897.37,
      973292578.86,
      1828276010.88,
      720553874.51,
      390940683.1
    ]
  ],
  "SZ002945": [
    [
      1395355967.1,
      1489800611.89,
      1010603099.5,
      1000843794.61,
      1067185983.74,
      1318353295.03,
      1668857767.74,
      706314130.44,
      643707107.24
    ],
    [
      483726211.7,
      812496331.45,
      441666561.99,
      344672483.7,
      463150384.86,
      589118277.95,
      815994245.57,
      188093452.91,
      77059907.92
    ]
  ]
}