Browse Source

update: change from mobile to PC

master
Dnomd343 2 years ago
parent
commit
0876f504fb
  1. 11
      src/ixsw.la/catalog.py

11
src/wap.ixsw.la/catalog.py → src/ixsw.la/catalog.py

@ -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/'))
))
Loading…
Cancel
Save