1 # -*- coding=utf8 -*- 2 3 import requests 4 from bs4 import BeautifulSoup 5 6 def qiushibaike(): 7 content = requests.get(‘http://www.qiushibaike.com‘).content 8 soup = BeautifulSoup(content, ‘html.parser‘) 9 10 for div in soup.find_all(‘div‘, {‘class‘ : ‘content‘}): 11 print div.text.strip() 12 13 def ustcjob(): 14 headers = {‘User-Agent‘:‘Mozilla / 5.0(X11;Linux x86_64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 50.0.2661.102 Safari / 537.36‘} 15 content = requests.get(‘http://job.ustc.edu.cn/list.php?MenuID=002‘, headers = headers).content 16 soup = BeautifulSoup(content, ‘html.parser‘) 17 18 for Jop in soup.find_all(‘div‘, {‘class‘ : ‘Joplistone‘}): 19 for item in Jop.find_all(‘li‘): 20 print "%-30s%-20s%-40s" % (item.a.text.strip() , item.span.text.strip() , item.span.next_sibling.text.strip()) 21 22 23 if __name__ == ‘__main__‘: 24 #qiushibaike() 25 ustcjob()
四.实现效果
原文:https://www.cnblogs.com/qq991025/p/11831776.html