Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,63 @@ import re
|
|
7 |
from googlesearch import search
|
8 |
from urllib.parse import parse_qs
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def run_lora(prompt,site,start,end):
|
11 |
url = ("https://www.google.com/search?q=inurl:" +site + " " +prompt + "&tbs=cdr%3A1%2Ccd_min%3A"+start+"%2Ccd_max%3A" + end)
|
12 |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
|
@@ -69,7 +126,7 @@ with gr.Blocks() as app:
|
|
69 |
translated_textbox = gr.Textbox(lines=5, placeholder="", label="Result Text")
|
70 |
info_label = gr.HTML("")
|
71 |
btn = gr.Button("GetNow")
|
72 |
-
btn.click(
|
73 |
|
74 |
app.queue()
|
75 |
app.launch()
|
|
|
7 |
from googlesearch import search
|
8 |
from urllib.parse import parse_qs
|
9 |
|
10 |
+
from selenium import webdriver
|
11 |
+
from selenium.webdriver.common.keys import Keys
|
12 |
+
from selenium.webdriver.common.by import By
|
13 |
+
import time
|
14 |
+
|
15 |
+
# Đường dẫn tới ChromeDriver của bạn
|
16 |
+
PATH = "path_to_chromedriver" # Thay đổi đường dẫn nếu cần
|
17 |
+
driver = webdriver.Chrome(PATH)
|
18 |
+
|
19 |
+
def google_search_with_time_filter(query, start_date, end_date):
|
20 |
+
# Mở trang Google
|
21 |
+
driver.get("https://www.google.com")
|
22 |
+
|
23 |
+
# Tìm thanh tìm kiếm và nhập từ khóa
|
24 |
+
search_box = driver.find_element(By.NAME, "q")
|
25 |
+
search_box.send_keys(query)
|
26 |
+
search_box.send_keys(Keys.RETURN)
|
27 |
+
|
28 |
+
# Nhấn vào nút "Công cụ"
|
29 |
+
tools_button = driver.find_element(By.XPATH, "//div[@aria-label='Công cụ']")
|
30 |
+
tools_button.click()
|
31 |
+
|
32 |
+
# Nhấn vào nút "Bất kỳ lúc nào"
|
33 |
+
any_time_button = driver.find_element(By.XPATH, "//div[text()='Bất kỳ lúc nào']")
|
34 |
+
any_time_button.click()
|
35 |
+
|
36 |
+
# Chọn phạm vi thời gian
|
37 |
+
custom_range_button = driver.find_element(By.XPATH, "//li//span[text()='Phạm vi tùy chỉnh']")
|
38 |
+
custom_range_button.click()
|
39 |
+
|
40 |
+
# Nhập ngày bắt đầu và ngày kết thúc
|
41 |
+
start_date_input = driver.find_element(By.XPATH, "//input[@aria-label='Ngày bắt đầu']")
|
42 |
+
end_date_input = driver.find_element(By.XPATH, "//input[@aria-label='Ngày kết thúc']")
|
43 |
+
start_date_input.send_keys(start_date)
|
44 |
+
end_date_input.send_keys(end_date)
|
45 |
+
end_date_input.send_keys(Keys.RETURN)
|
46 |
+
|
47 |
+
# Đợi trang tải kết quả
|
48 |
+
time.sleep(2)
|
49 |
+
|
50 |
+
# Lấy các kết quả
|
51 |
+
results = driver.find_elements(By.CLASS_NAME, "tF2Cxc")
|
52 |
+
|
53 |
+
# Hiển thị kết quả
|
54 |
+
for result in results[:5]: # Lấy 5 kết quả đầu tiên
|
55 |
+
title = result.find_element(By.TAG_NAME, "h3").text
|
56 |
+
link = result.find_element(By.TAG_NAME, "a").get_attribute("href")
|
57 |
+
print(f"Title: {title}")
|
58 |
+
print(f"Link: {link}")
|
59 |
+
print('-' * 80)
|
60 |
+
|
61 |
+
# Thực hiện tìm kiếm với bộ lọc thời gian
|
62 |
+
google_search_with_time_filter("Python programming", "01/01/2023", "12/31/2023")
|
63 |
+
|
64 |
+
# Đóng trình duyệt sau khi hoàn tất
|
65 |
+
driver.quit()
|
66 |
+
|
67 |
def run_lora(prompt,site,start,end):
|
68 |
url = ("https://www.google.com/search?q=inurl:" +site + " " +prompt + "&tbs=cdr%3A1%2Ccd_min%3A"+start+"%2Ccd_max%3A" + end)
|
69 |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
|
|
|
126 |
translated_textbox = gr.Textbox(lines=5, placeholder="", label="Result Text")
|
127 |
info_label = gr.HTML("")
|
128 |
btn = gr.Button("GetNow")
|
129 |
+
btn.click(google_search_with_time_filter, inputs=["site:" + input_sitebox +" " + input_textbox,start,end],outputs=[translated_textbox])
|
130 |
|
131 |
app.queue()
|
132 |
app.launch()
|