Created
March 30, 2025 16:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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