Python Forum

Full Version: search API calls in different format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Yacy is a self-host search engine with an API

When I search via the web panel it produces real results in JSON format. For example searching "python":
https://search.simplifiedprivacy.is/yacy...ery=python

But when I try do it via python, it shows up with weird URLs like “yacysearch.json?query=python” in the URLs and a totally different format.

here's the code I used to test:


import requests
import json
entry = input("Enter search:")
api_url1 = f"https://search.simplifiedprivacy.is/yacysearch.json?query={entry}"
response1 = requests.get(api_url1)
round2 = response1.json()
pretty = json.dumps(round2, indent=2)
print(pretty)
I don't know what you are typing in for 'entry', but the following works fine:
>>> import requests
>>> import json
>>> 
>>> response = requests.get("https://search.simplifiedprivacy.is/yacysearch.json?query=python")
>>> response.status_code
200
>>>
Yeah but if I print() the JSON, then the URLs are mangled.
any opinion on this mangled URL issue? thank you
I did not have a problem just using your code, the output of pretty is 2390 lines, which I will not copy here.

I have, for example:

Output:
"link": "https://www.linuxquestions.org/questions/syndicated-linux-news-67/lxer-python-python-python-aka-python-3-a-745438-print/"
and

Output:
"image": "https://www.linuxquestions.org/questions/images/LinuxQuestions.png",
The latter shows those cute little penguins if pasted in my browser!

Both links work fine. Both are unmangled.