adpro commited on
Commit
7d4e9a8
·
verified ·
1 Parent(s): a823bf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -8,20 +8,27 @@ from googlesearch import search
8
  from urllib.parse import parse_qs
9
 
10
  def run_lora(prompt,site,start,end):
 
 
 
11
  murl = "https://www.google.com/search?q=site:" +site + " " +prompt + "&sca_esv=9a56963d0daaccd0&sca_upv=1&tbs=cdr%3A1%2Ccd_min%3A"+start+"%2Ccd_max%3A" + end
12
  surl = "https://www.google.com/search?q=site:" +site + " " +prompt + "after:"+start+"before:" + end
13
  page = requests.get(murl)
14
  print("https://www.google.com/search?q=site:" +site + " " +prompt + "&tbs=cdr%3A1%2Ccd_min%3A"+start+"%2Ccd_max%3A" + end)
15
- soup = BeautifulSoup(page.content)
16
  import re
17
- links = soup.findAll("a")
18
- mLink=""
19
- #for link in soup.find_all("a", "html.parser", parse_only=SoupStrainer('a')):
20
- for link in soup.find_all("a",href=re.compile("(?<=/url\?q=)(htt.*://.*)")):
21
- #print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
22
- j = re.split(":(?=http)",link["href"].replace("/url?q=",""))
23
- mLink+= "\n" + str(j)
24
- return mLink
 
 
 
 
25
 
26
  def extract_href(href):
27
  url = urlparse(href)
 
8
  from urllib.parse import parse_qs
9
 
10
  def run_lora(prompt,site,start,end):
11
+
12
+
13
+
14
  murl = "https://www.google.com/search?q=site:" +site + " " +prompt + "&sca_esv=9a56963d0daaccd0&sca_upv=1&tbs=cdr%3A1%2Ccd_min%3A"+start+"%2Ccd_max%3A" + end
15
  surl = "https://www.google.com/search?q=site:" +site + " " +prompt + "after:"+start+"before:" + end
16
  page = requests.get(murl)
17
  print("https://www.google.com/search?q=site:" +site + " " +prompt + "&tbs=cdr%3A1%2Ccd_min%3A"+start+"%2Ccd_max%3A" + end)
18
+ soup = BeautifulSoup(page.text,'html.parser')
19
  import re
20
+ search_results = []
21
+ for g in soup.find_all('div', class_='tF2Cxc'):
22
+ title = g.find('h3').text if g.find('h3') else 'No title'
23
+ link = g.find('a')['href']
24
+ snippet = g.find('div', class_='IsZvec').text if g.find('div', class_='IsZvec') else 'No snippet'
25
+ search_results.append({
26
+ 'title': title,
27
+ 'link': link,
28
+ 'snippet': snippet
29
+ })
30
+
31
+ return search_results
32
 
33
  def extract_href(href):
34
  url = urlparse(href)