程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python爬蟲

編輯:Python
import requests
import random
url = 'http://fund.eastmoney.com/data/rankhandler.aspx'
headers={

'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Cookie': 'qgqp_b_id=24f527c7b8ec9f0e4624fa644a994120; ' \
'EMFUND1=null; EMFUND2=null; EMFUND3=null; EMFUND4=null; EMFUND5=null; ' \
'AUTH_FUND.EASTMONEY.COM_GSJZ=AUTH*TTJJ*TOKEN; EMFUND0=null; ' \
'EMFUND6=03-07%2014%3A13%[email protected]%23%24%u91D1%u4FE1%u6C11%u5174%u503A%[email protected]%23%24004400; ' \
'EMFUND7=03-07%2021%3A45%[email protected]%23%24%u540C%u6CF0%u5927%u5065%u5EB7%u4E3B%u9898%u6DF7%[email protected]%23%24011002; ' \
'EMFUND8=03-07%2021%3A35%[email protected]%23%24%u524D%u6D77%u5F00%u6E90%u6CAA%u6E2F%u6DF1%u519C%u4E1A%u6DF7%[email protected]%23%24164403; ' \
'EMFUND9=03-10 16:52:[email protected]#$%u6613%u65B9%u8FBE%u7B56%u7565%u6210%u957F%u6DF7%[email protected]%23%24110002; em_hq_fls=js; ' \
'HALis=a-sz-300059-%u4E1C%u65B9%u8D22%u5BCC%2Ca-sz-002667-%u978D%u91CD%u80A1%u4EFD; _adsame_fullscreen_16928=1; ' \
'st_si=62786453084976; st_asi=delete; ASP.NET_SessionId=c0djrvxhnnjzfgrsummunfcu; st_pvi=34135657244968; ' \
'st_sp=2022-03-06%2023%3A31%3A38; st_inirUrl=https%3A%2F%2Fwww.baidu.com%2Flink; st_sn=8; st_psi=20220312205308995-112200304021-2152809199',
'Host': 'fund.eastmoney.com',
'Referer': 'http://fund.eastmoney.com/data/fundranking.html',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36'}
content_list=[]
for i in range(1,3): #獲取前兩頁
v_value = random.random()
params={
'op':'ph','dt':'kf','ft':'all','rs':'','gs':'0',
'sc':'rzdf','st':'desc','sd':'2021-03-12',
'ed':'2022-03-12','qdii':'','tabSubtype':',,,,,',
'pi':i,'pn':'50','dx':'1','v':v_value}
response=requests.get(url=url,headers=headers,params=params)
response.encode = 'utf8'
print(response.status_code)
content=response.text
content=content[:content.find('"]')].replace("var rankData = {datas:[", "")
for i in content.split('"'):
if len(i.split(',')) < 10:
continue
order = i.split(',')
content_list.append(order)
for i in content_list:
print(i)

實現效果


  1. 上一篇文章:
  2. 下一篇文章:
相關文章
    没有相关文章
Copyright © 程式師世界 All Rights Reserved