Skip to content

Instantly share code, notes, and snippets.

@zengxinhui
Created March 30, 2025 16:04
Show Gist options
  • Save zengxinhui/927f3b3afa962ac118572a1eb97753c7 to your computer and use it in GitHub Desktop.
Save zengxinhui/927f3b3afa962ac118572a1eb97753c7 to your computer and use it in GitHub Desktop.
given a book title, find it's category according to gzlib.org.cn
import requests, re
filename='Books.txt'
def gzlib(q):
url=f'https://opac.gzlib.org.cn/opac/search?q={q}&searchWay=title'
response = requests.get(url)
bookrecno = set(re.findall(r'bookDetail\((\d+)', response.text))
if len(bookrecno) == 1:
bookrecno = bookrecno.pop()
url=f'https://opac.gzlib.org.cn/opac/book/callnos?bookrecnos={bookrecno}'
response = requests.get(url)
return re.findall(r'CDATA\[(.*?)]', response.text)
else:
return []
for x in open(filename).read().splitlines():
print(x, gzlib(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment