In [2]:
import requests
In [3]:
import json
In [4]:
import re
In [14]:
headers ={“User-Agent”:”Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36″,}
In [17]:
url = “http://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E7%8E%8B%E7%BE%B2%E4%B9%8B%E4%B9%A6%E6%B3%95%E5%9B%BE%E7%89%87&hs=0&pn=5&spn=0&di=86240&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=2104568389%2C1361002752&os=1412431185%2C3611362453&simid=4201550956%2C905379117&adpicid=0&lpn=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=%E7%8E%8B%E7%BE%B2%E4%B9%8B%E4%B9%A6%E6%B3%95%E5%9B%BE%E7%89%87&objurl=http%3A%2F%2Fhiphotos.baidu.com%2Fjtan62%2Fpic%2Fitem%2F178ae41555bff10a21a4e937.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fks52_z%26e3Bftgw_z%26e3Bv54_z%26e3BvgAzdH3FfAzdH3Fks52_mvu19ldka8aaox10_z%26e3Bip4s&gsm=0&islist=&querylist=http://image.baidu.com/pcdutu/a_upload?fr=html5&target=pcSearchImage&needhttp://image.baidu.com/pcdutu/a_upload?fr=html5&target=pcSearchImage&needJson=trueJson=true”
files = {‘file’:open(“test.jpg”,”rb”)}
temp_data = json.loads(requests.post(url=url,headers=headers,files=files).text)
—————————————————————————
FileNotFoundError Traceback (most recent call last)
1 url = “http://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E7%8E%8B%E7%BE%B2%E4%B9%8B%E4%B9%A6%E6%B3%95%E5%9B%BE%E7%89%87&hs=0&pn=5&spn=0&di=86240&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=2104568389%2C1361002752&os=1412431185%2C3611362453&simid=4201550956%2C905379117&adpicid=0&lpn=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=%E7%8E%8B%E7%BE%B2%E4%B9%8B%E4%B9%A6%E6%B3%95%E5%9B%BE%E7%89%87&objurl=http%3A%2F%2Fhiphotos.baidu.com%2Fjtan62%2Fpic%2Fitem%2F178ae41555bff10a21a4e937.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fks52_z%26e3Bftgw_z%26e3Bv54_z%26e3BvgAzdH3FfAzdH3Fks52_mvu19ldka8aaox10_z%26e3Bip4s&gsm=0&islist=&querylist=http://image.baidu.com/pcdutu/a_upload?fr=html5&target=pcSearchImage&needhttp://image.baidu.com/pcdutu/a_upload?fr=html5&target=pcSearchImage&needJson=trueJson=true”
—-> 2 files = {‘file’:open(“test.jpg”,”rb”)}
3 temp_data = json.loads(requests.post(url=url,headers=headers,files=files).text)
FileNotFoundError: [Errno 2] No such file or directory: ‘test.jpg’
In [9]:
ans_url = “http://image.baidu.com/pcdutu?queryImageUrl=” + str(temp_data[‘url’]) + “&querySign” + temp_data[“querySign”] + “&fm=home&uptype=upload_pc&result=result_camera”
page_source= requests.get(url=ans_url,headers=headers).text
guessWord = re.findall(“‘guessWord’: ‘(.*?)'”,page_source)[0]
term_data = re.findall(‘”name”:”(.*?)”,”baike”:{“url”:”(.*?)”,”abstract”:”(.*?)”,”‘,page_source)
—————————————————————————
NameError Traceback (most recent call last)
—-> 1 ans_url = “http://image.baidu.com/pcdutu?queryImageUrl=” + str(temp_data[‘url’]) + “&querySign” + temp_data[“querySign”] + “&fm=home&uptype=upload_pc&result=result_camera”
2 page_source= requests.get(url=ans_url,headers=headers).text
3 guessWord = re.findall(“‘guessWord’: ‘(.*?)'”,page_source)[0]
4 term_data = re.findall(‘”name”:”(.*?)”,”baike”:{“url”:”(.*?)”,”abstract”:”(.*?)”,”‘,page_source)
NameError: name ‘temp_data’ is not defined
In [10]:
if guessWord:
print(“The picture may be:”,guessWord)
—————————————————————————
NameError Traceback (most recent call last)
—-> 1 if guessWord:
2 print(“The picture may be:”,guessWord)
NameError: name ‘guessWord’ is not defined
In [11]:
print(“It also may be:”)else:
File “
print(“It also may be:”)else:
^
SyntaxError: invalid syntax
In [12]:
print(“The most possible may be :”)for eve in term_data:
File “
print(“The most possible may be :”)for eve in term_data:
^
SyntaxError: invalid syntax
In [13]:
print(“名称:”,eve[0],”\t描述:”,eve[2],”\t百科地址:”,eve[1])
—————————————————————————
NameError Traceback (most recent call last)
—-> 1 print(“名称:”,eve[0],”\t描述:”,eve[2],”\t百科地址:”,eve[1])
NameError: name ‘eve’ is not defined
In [ ]:
In [ ]:
In [ ]:
In [ ]: