import requests
import urllib.parse
import sys
import json
url = "https://google-search3.p.rapidapi.com/api/v1/serp/"

q=urllib.parse.quote("幸福空間")
#q=urllib.parse.quote("設計師")

print(q)
pl={'query':'q='+q+'&num=100','website':'https://rapidapi.com'}
payload=str(pl)
#payload = '{"query": "q={}&num=100",  "website": "https://rapidapi.com" }'.format(q)

#print(payload)


headers = {
    'content-type': "application/json",
    'x-rapidapi-key': "6dd30886e0msh7aefc9a0a794398p1896f2jsn275c45475609",
    'x-rapidapi-host': "google-search3.p.rapidapi.com"
    }

#response = requests.request("POST", url, data=payload.replace("'",'"'), headers=headers)

url = "https://google-search3.p.rapidapi.com/api/v1/search/q="+payload+"&cr=countryTW&num=10"

response = requests.request("GET", url, headers=headers)


print(response.text)
js=json.loads(response.text)
print(js)
excludes=['youtube','facebook','twitter']
for r in js['results']:
    for ee in excludes:
        if 'youtube' not in r['link']:
            print(r['title'])
            print(r['link'])

sys.exit()
