python
1 2import requests 3from bs4 import BeautifulSoup 4 5 6def main(): 7 8 # connpass の PyNumon#8 のイベント参加者・申込者一覧のURL 9 url = 'https://python-nyumon.connpass.com/event/100817/participation' 10 11 # requests で参加者一覧の情報と取得する 12 response = requests.get(url) 13 14 # response から HTML 部分(content) を取得 15 content = response.content 16 17 # BeautifulSoup に content を渡して解析の準備をする 18 soup = BeautifulSoup(content, 'html.parser') 19 20 # <div class="participation_table_area mb_18"> に該当するものを取り出す 21 # participation_tables は List 22 participation_tables = soup.find_all('div', class_='participation_table_area mb_20') 23 24 # participation_tables を順番に見て、"講師・メンター枠"の情報を取り出す 25 for participation_table in participation_tables: 26 # <table><thead><tr><th> に該当するタグの要素を取り出す (参加者枠の種類が記載されているので) 27 participant_type = participation_table.table.thead.tr.th.get_text() 28 29 # 参加者枠を示す文字に "講師・メンター枠" が含まれるものを取り出す 30 if '通常参加枠' in participant_type: 31 mentors_table = participation_table 32 break 33 34 # 講師・メンター枠の HTML の中で class=display_name に該当するものを取り出す 35 # mentor_names は List 36 mentor_names = mentors_table.find_all(class_='display_name') 37 38 # 取り出した 講師・メンター枠の要素から純粋な名前だけを取り出す(前後の無駄な空行や改行などを取り除く) 39 for mentor_name in mentor_names: 40 print(mentor_name.get_text().strip()) 41 42 43if __name__ == '__main__': 44 main() 45 46 47 48
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/02 14:54
2018/12/02 15:23
2018/12/02 16:02
2018/12/02 16:08
2018/12/03 02:36
2018/12/03 03:14
2018/12/03 04:39
2018/12/03 12:57
2018/12/03 14:22
2018/12/03 14:26
2018/12/03 15:04
2018/12/05 07:21
2018/12/05 10:19
2018/12/31 05:58