Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -122,10 +122,13 @@ def translate_query(query, country):
|
|
| 122 |
print(f"Translation error: {str(e)}")
|
| 123 |
return query
|
| 124 |
|
| 125 |
-
def search_serphouse(query, country, page=1, num_result=
|
| 126 |
url = "https://api.serphouse.com/serp/live"
|
| 127 |
|
|
|
|
| 128 |
translated_query = translate_query(query, country)
|
|
|
|
|
|
|
| 129 |
|
| 130 |
payload = {
|
| 131 |
"data": {
|
|
@@ -134,12 +137,17 @@ def search_serphouse(query, country, page=1, num_result=100):
|
|
| 134 |
"loc": COUNTRY_LOCATIONS.get(country, "United States"),
|
| 135 |
"lang": "en",
|
| 136 |
"device": "desktop",
|
| 137 |
-
"serp_type": "
|
| 138 |
"page": "1",
|
| 139 |
-
"
|
|
|
|
|
|
|
| 140 |
}
|
| 141 |
}
|
| 142 |
|
|
|
|
|
|
|
|
|
|
| 143 |
headers = {
|
| 144 |
"accept": "application/json",
|
| 145 |
"content-type": "application/json",
|
|
@@ -148,13 +156,16 @@ def search_serphouse(query, country, page=1, num_result=100):
|
|
| 148 |
|
| 149 |
try:
|
| 150 |
response = requests.post(url, json=payload, headers=headers)
|
| 151 |
-
print("Request payload:", json.dumps(payload, indent=2))
|
| 152 |
print("Response status:", response.status_code)
|
|
|
|
| 153 |
|
| 154 |
response.raise_for_status()
|
| 155 |
return {"results": response.json(), "translated_query": translated_query}
|
| 156 |
except requests.RequestException as e:
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
def format_results_from_raw(response_data):
|
| 160 |
if "error" in response_data:
|
|
|
|
| 122 |
print(f"Translation error: {str(e)}")
|
| 123 |
return query
|
| 124 |
|
| 125 |
+
def search_serphouse(query, country, page=1, num_result=10):
|
| 126 |
url = "https://api.serphouse.com/serp/live"
|
| 127 |
|
| 128 |
+
# 검색어 번역
|
| 129 |
translated_query = translate_query(query, country)
|
| 130 |
+
print(f"Original query: {query}")
|
| 131 |
+
print(f"Translated query: {translated_query}")
|
| 132 |
|
| 133 |
payload = {
|
| 134 |
"data": {
|
|
|
|
| 137 |
"loc": COUNTRY_LOCATIONS.get(country, "United States"),
|
| 138 |
"lang": "en",
|
| 139 |
"device": "desktop",
|
| 140 |
+
"serp_type": "web", # web으로 변경
|
| 141 |
"page": "1",
|
| 142 |
+
"num_result": "10", # num_result로 변경
|
| 143 |
+
"verbatim": "0",
|
| 144 |
+
"gfilter": "0"
|
| 145 |
}
|
| 146 |
}
|
| 147 |
|
| 148 |
+
# API 요청 디버깅을 위한 출력
|
| 149 |
+
print("Full payload:", json.dumps(payload, indent=2, ensure_ascii=False))
|
| 150 |
+
|
| 151 |
headers = {
|
| 152 |
"accept": "application/json",
|
| 153 |
"content-type": "application/json",
|
|
|
|
| 156 |
|
| 157 |
try:
|
| 158 |
response = requests.post(url, json=payload, headers=headers)
|
|
|
|
| 159 |
print("Response status:", response.status_code)
|
| 160 |
+
print("Response content:", response.text[:500]) # 응답 내용 확인
|
| 161 |
|
| 162 |
response.raise_for_status()
|
| 163 |
return {"results": response.json(), "translated_query": translated_query}
|
| 164 |
except requests.RequestException as e:
|
| 165 |
+
error_msg = f"Error: {str(e)}"
|
| 166 |
+
if hasattr(response, 'text'):
|
| 167 |
+
error_msg += f"\nResponse content: {response.text}"
|
| 168 |
+
return {"error": error_msg, "translated_query": query}
|
| 169 |
|
| 170 |
def format_results_from_raw(response_data):
|
| 171 |
if "error" in response_data:
|