from pyquery import PyQuery as pq
import re,time,requests,json
a=1
while a==1:
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
shuming=input("输入要查询的书:")
aaa=pq(f'http://113.200.60.162:8090/opac/search?q={shuming}')
yema=aaa('#resultTile > div:nth-child(3) > span').text()
yema1=re.findall('\d+',yema)
if yema1:
yema2=(int(yema1[0]))+1
print(f'总共搜索到{yema2-1}页')
for i in range(1,yema2):
aaa1=requests.get(f'http://113.200.60.162:8090/opac/search?q={shuming}&searchType=standard&isFacet=true&view=standard&rows=10&sortWay=score&sortOrder=desc&searchWay0=marc&logical0=AND&page={i}',headers=headers).text
aaa2=pq(aaa1)
time.sleep(0.5)
print(f'第{i}页')
for i in aaa2('.resultList >.resultTable > tr').items():
print (i('td').eq(1).text(),'\t',end="")
print (i('.bookmetaTitle > a').text(),'\t'.format(chr(12288)),end="")
print ('\t',i('td.bookmetaTD > div.bookmeta > div:nth-child(2)').text(),'\t'.format(chr(12288)))
bianma=str((i('.bookmeta').attr('bookrecno')))
if bianma:
# print (bianma)
# time.sleep(0.5)
bianma2=f'http://113.200.60.162:8090/opac/book/holdingPreviews?bookrecnos={bianma}&curLibcodes=&return_fmt=json'
bianma3=requests.get(bianma2,headers=headers,timeout=3).text
time.sleep(1)
if bianma3:
#s输出json页面
lrc=json.loads(bianma3)
# print (bianma3)
# print(lrc)
previews= lrc.get('previews')
previews1= previews.get(bianma)
if previews1:
for i1 in range(len(previews1)):
previews2=previews1[i1]
print()
print(previews2['curlibName'],'\t',end="")
print(previews2['curlocalName'],'\t',end="")
print(previews2['callno'],end="")
# print(previews1[i],end="")
# previews2=previews1[i]
# print(previews2['callno'],previews2['curlibName'],previews2['curlocalName'])
print()
print()
print()
print('查下下一页,稍等几秒')
time.sleep(5)
else:
print("没有相关书籍")
python爬西安市图书馆书籍查询
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...