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('孔夫子旧书网图书信息抓取结束。。。')
#代码可以直接运行,仅供参考学习交流