python 實現抓取孔夫子舊書網圖書圖片
阿新 • • 發佈:2018-12-21
import requests from bs4 import BeautifulSoup from fake_useragent import UserAgent import json #孔夫子舊書網圖書資訊抓取 def getImg(isbn): ua = UserAgent() headers = {'User-Agent':ua.random} url = 'http://seller.kongfz.com/pc/booklib/search?key='+isbn+'&pagenum=1' data = requests.get(url,headers=headers) #print(url) json_data = json.loads(data.text) #print(dict(json_data)['data']) data = dict(json_data)['data'] src = [] if len(data) > 0: po = dict(data) #print(po['list']) lst = list(po['list']) #print(lst) dict2 = dict(lst[0]) #print(dict2) #print(dict2['imgSrc']) #print(po['list']) if len(dict2['imgSrc']) > 0: src.append(dict2['imgSrc']) return src if __name__=='__main__': print('孔夫子舊書網圖書資訊抓取開始。。。') img = getImg('9787115474209') print('img=',img) print('孔夫子舊書網圖書資訊抓取結束。。。')
#程式碼可以直接執行,僅供參考學習交流