1. 程式人生 > >Python爬蟲-爬取騰訊QQ招聘崗位資訊(Beautiful Soup)

Python爬蟲-爬取騰訊QQ招聘崗位資訊(Beautiful Soup)

爬取騰訊招聘資訊-Beautiful Soup 

---------------------------------------

============================================

===========================================================

================================================

===================================================

 1 '''
 2
爬取騰訊招聘的網站 https://hr.tencent.com/position.php?&start=10#a 3 4 ''' 5 6 from bs4 import BeautifulSoup 7 from urllib import request 8 9 10 11 def qq(): 12 # 獲取頁面 13 url = 'https://hr.tencent.com/position.php?&start=10#a' 14 rsp = request.urlopen(url) 15 html = rsp.read() 16
17 18 # 提取資料 19 # 用bs解析,lxml驅動 20 soup = BeautifulSoup(html, 'lxml') 21 22 # 建立css選擇器,得到相應的tags,even/odd,奇數偶數行,一行一個崗位資訊,trs = tr1 + tr2 得到所有崗位資訊 23 tr1 = soup.select("tr[class='even']") 24 tr2 = soup.select("tr[class='odd']") 25 trs = tr1 + tr2 26 27 for tr in trs:
28 name = tr.select('td a')[0].get_text() 29 print(name) 30 href = tr.select('td a')[0].attrs['href'] 31 print(href) 32 catalog = tr.select('td')[1].get_text() 33 print(catalog) 34 location = tr.select('td')[3].get_text() 35 print(location) 36 print("==" * 12) 37 38 if __name__ == '__main__': 39 qq()