返回提交历史
Modified
g4f/Provider/search/GoogleSearch.py
+5
-5
XFEstudio/gpt4free
Update GoogleSearch.py
721d0f26
代码差异
1 个文件
+5
-5
@@ -32,7 +32,7 @@ class GoogleSearch(AsyncGeneratorProvider, ProviderModelMixin):
32
32
search_url = f"{cls.url}/search?q={urllib.parse.quote_plus(query)}"
33
33
34
34
debug.log(f"Google Search: Starting CDPSession for query: {query}")
35
session = CDPSession(headless=False)
35
session = CDPSession(headless=True)
36
36
await session.start()
37
37
38
38
try:
@@ -42,12 +42,12 @@ class GoogleSearch(AsyncGeneratorProvider, ProviderModelMixin):
42
42
await session.close()
43
43
raise e
44
44
45
# Enable AI mode if the model is like "ai"
45
# Enable AI mode if model is ai-mode
46
46
try:
47
47
if model == "ai-mode":
48
48
await session.wait_for_network_idle(idle_time=1, timeout=10.0)
49
49
for _ in range(10):
50
result = await session.evaluate_js("""const b =Array.from(document.querySelectorAll("a, button")).filter(a=>a.textContent.endsWith("KI‑Modus")).pop(); b ? b.click() : null; !!b""")
50
result = await session.evaluate_js("""const b =Array.from(document.querySelectorAll("a, button")).filter(a=>a.textContent.endsWith("KI‑Modus") || a.textContent.endsWith("AI-Mode")).pop(); b ? b.click() : null; !!b""")
51
51
debug.log(f"Google Search: Attempted #{_+1} to enable AI mode, result: {result}")
52
52
await asyncio.sleep(1)
53
53
if not result:
@@ -74,7 +74,7 @@ for (const nodes of Array.from(document.querySelector('[decode-data-ved="1"]').q
74
74
for (const node of nodes) {result.push(node)}
75
75
}
76
76
77
const lines = result.map(n=>n.textContent).filter(c=>!c.startsWith('TgQPHd|'));
77
const lines = result.map(n=>n.textContent);
78
78
const keepLines = { };
79
79
80
80
for (let l of lines) {
@@ -86,7 +86,7 @@ for (let l of lines) {
86
86
const imgMatch = l.match(/_setImageSrc\\([^,]+,\\s*'([^']+)'\\)/);
87
87
if (imgMatch) {
88
88
// Bereinigt eventuelle doppelte Backslashes aus dem Daten-String (z.B. data:image\\/png)
89
l = `\\n`;
89
l = `\\n.replaceAll('\\', '')})`;
90
90
}
91
91
const fileMath = l.match(/\\[\\{.+\\]^/);
92
92
if (fileMath) {