|
|
@ -32,14 +32,17 @@ def httpRequest(url: str) -> str: # fetch raw html content |
|
|
|
def extractCatalog(rawHtml: str) -> dict: # extract catalog from html content |
|
|
|
catalog = {} |
|
|
|
html = BeautifulSoup(rawHtml, 'lxml') |
|
|
|
div = html.select('div[class="directoryArea"]')[0] |
|
|
|
for item in div.select('a[style=""]'): |
|
|
|
for item in html.select('dd'): |
|
|
|
item = item.select('a')[0] |
|
|
|
name = re.search(r'^(第\d+章)(.*)$', item.text) |
|
|
|
pageId = item.attrs['href'].replace('/ks82668/', '').replace('.html', '') |
|
|
|
catalog['%s %s' % (name[1], name[2].strip())] = pageId |
|
|
|
return catalog |
|
|
|
catalog = sorted(catalog.items(), key = lambda d: int( |
|
|
|
re.search(r'^第(\d+)章', d[0])[1] # sort by chapter |
|
|
|
)) |
|
|
|
return {x[0]: x[1] for x in catalog} # formatted output |
|
|
|
|
|
|
|
|
|
|
|
print(json.dumps( |
|
|
|
extractCatalog(httpRequest('https://wap.ixsw.la/ks82668/all.html')) |
|
|
|
extractCatalog(httpRequest('https://www.ixsw.la/ks82668/')) |
|
|
|
)) |