用python爬了厦门人才网的.net岗位
为了看看.net的就业行情怎么样,用python爬取了厦门人才网.net岗位的信息,话不多说上代码,python没学多久,如果有什么不妥请指正
1 import requests 2 from bs4 import BeautifulSoup 3 page = 1; 4 def loop(page): 5 url = "https://www.xmrc.com.cn/net/info/resultg.aspx?a=a&g=g&jobtype=&releaseTime=365&searchtype=1&keyword=.net&sortby=updatetime&ascdesc=Desc&PageIndex=%s"%page; 6 response = requests.get(url) 7 soup = BeautifulSoup(response.text, 'html.parser') 8 9 allJob = soup.select(".a4.js_companyName"); 10 11 12 companys = [] 13 Others = [] 14 for x in range(0,len(allJob)): 15 job = allJob[x].get_text().strip() 16 print(job); 17 other = allJob[x].parent.findPrevious("td").get_text().strip() + ","+ allJob[x].parent.findNext("td").get_text().strip() + "," + allJob[x].parent.findNext("td").findNext("td").get_text().strip(); 18 print(other); 19 companys.append(job) 20 Others.append(other) 21 return companys, Others; 22 23 for x in range(0,20): 24 companys,Others = loop(x) 25 with open('company.txt', 'a', encoding='utf-8') as f: 26 for x in range(0,len(companys)): 27 f.write(str(companys[x] + "," + Others[x]) + '\n')