45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
import os,sys
|
|
from pprint import pprint
|
|
from bs4 import BeautifulSoup
|
|
import requests
|
|
|
|
main_url = "https://www.mchk.org.hk/english/list_register/list.php?page=4&ipp=20&type=L"
|
|
req = requests.get(main_url)
|
|
soup = BeautifulSoup(req.text, "html.parser")
|
|
|
|
title = soup.find("h1")
|
|
|
|
trs = soup.select("table#Table_5 table tr")
|
|
|
|
for tr in trs[2:]:
|
|
try:
|
|
# name
|
|
tds = tr.select('td[headers="reg"]')
|
|
if (len(tds) > 0):
|
|
# reg field got something
|
|
print(tds[0].get_text())
|
|
|
|
# # name
|
|
tds = tr.select('td[headers="name"]')
|
|
print(tds[0].get_text())
|
|
|
|
# # qualification
|
|
tds = tr.select('td[headers="qualification"]')
|
|
print(tds[0].get_text())
|
|
print(tds[1].get_text())
|
|
pass
|
|
else:
|
|
# reg field got nothing
|
|
tds = tr.select('td[headers="qualification"]')
|
|
for i in range(0, len(tds), 2):
|
|
pprint(f'{tds[i].get_text()}, {tds[i+1].get_text()}')
|
|
pass
|
|
except Exception as e:
|
|
print(tr)
|
|
print(e)
|
|
print('error')
|
|
pass
|
|
|