天天看點

python爬取考研專業資訊

伴随着2021考研成績的公布,2021考研國家線也即将到來。大家是否有過考研的想法了?如果想考研我們就需要了解很多的資訊,但是百度的上有太多資訊需要我們去一一的鑒别,是比較浪費時間的。是以我們可以學習下簡單的資料采集,這樣我們就可以快速的從魚龍混雜的資訊中得到有價值的資訊。我們也可以通過爬蟲看看研招網有哪些專業,這樣也可以快速的幫助想考研的同學進行專業的選擇。這裡分享用Python寫的幾行代碼,很簡單,以下是代碼部分:

   #! -*- encoding:utf-8 -*-  

  import requests

  import random    

# 要通路的目标頁面  

targetUrl = "https://yz.chsi.com.cn/zsml/code/zy.do"  

  # 要通路的目标HTTPS頁面  

# targetUrl = "https://httpbin.org/ip"  

 # 代理伺服器(産品官網 www.16yun.cn)  

 proxyHost = "t.16yun.cn"  

 proxyPort = "31111"  

 # 代理驗證資訊  

proxyUser = "username"  

 proxyPass = "password"  

  proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {    

   "host" : proxyHost,    

   "port" : proxyPort,      

 "user" : proxyUser,    

  "pass" : proxyPass,    }

   # 設定 http和https通路都是用HTTP代理  

proxies = {      

"http"  : proxyMeta,    

  "https" : proxyMeta,    }  

 #  設定IP切換頭  

tunnel = random.randint(1,10000)  

 headers = {"Proxy-Tunnel": str(tunnel)}  

 resp = requests.get(targetUrl, proxies=proxies, headers=headers)

   print resp.status_code  

print resp.text