()
| 9 | |
| 10 | |
| 11 | def SearchResults(): |
| 12 | lis = [] |
| 13 | f = open("Input", "r") |
| 14 | header = { |
| 15 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" |
| 16 | } |
| 17 | StabUrl = "https://www.google.com/search?rlz=1C1CHBD_enIN872IN872&sxsrf=ALeKk03OHYAnSxX60oUwmblKn36Hyi8MhA%3A1600278715451&ei=u1BiX9ibG7qU4-EP_qGPgA8&q=" |
| 18 | midUrl = "&oq=" |
| 19 | EndUrl = "&gs_lcp=CgZwc3ktYWIQAzoECAAQR1C11AxYtdQMYJXcDGgAcAF4AIABpQKIAaUCkgEDMi0xmAEAoAECoAEBqgEHZ3dzLXdpesgBCMABAQ&sclient=psy-ab&ved=0ahUKEwiY5YDjnu7rAhU6yjgGHf7QA_AQ4dUDCA0&uact=5" |
| 20 | for i in f: |
| 21 | singleLink = [] |
| 22 | singleRatio = [] |
| 23 | singleWrite = [] |
| 24 | singleWrite.append(i.strip("\n")) |
| 25 | checkString = i.replace("+", "") |
| 26 | searchString = i.replace("+", "%2B") |
| 27 | searchString = searchString.replace(" ", "+") |
| 28 | searchString = StabUrl + searchString + midUrl + searchString + EndUrl |
| 29 | r = requests.get(searchString, headers=header) |
| 30 | soup = bs4.BeautifulSoup(r.text, features="html.parser") |
| 31 | elements = soup.select(".r a") |
| 32 | for g in elements: |
| 33 | lis.append(g.get("href")) |
| 34 | for k in lis: |
| 35 | sentence = "" |
| 36 | if (k[0] != "#") and k[0] != "/": |
| 37 | checker = k[8:16] |
| 38 | if checker != "webcache": |
| 39 | rr = requests.get(k, headers=header, verify=False) |
| 40 | soupInside = bs4.BeautifulSoup(rr.text, features="html.parser") |
| 41 | elementInside = soupInside.select("body") |
| 42 | for line in elementInside: |
| 43 | sentence = sentence + line.text |
| 44 | ratio = fuzz.token_set_ratio(sentence, checkString) |
| 45 | if ratio > 80: |
| 46 | singleLink.append(k) |
| 47 | singleRatio.append(ratio) |
| 48 | if len(singleLink) >= 4: |
| 49 | singleLink = np.array(singleLink) |
| 50 | singleRatio = np.array(singleRatio) |
| 51 | inds = singleRatio.argsort() |
| 52 | sortedLink = singleLink[inds] |
| 53 | sortedFinalList = list(sortedLink[::-1]) |
| 54 | sortedFinalList = sortedFinalList[:4] |
| 55 | FinalResult.append(singleWrite + sortedFinalList) |
| 56 | elif (len(singleLink) < 4) and len(singleLink) > 0: |
| 57 | singleLink = np.array(singleLink) |
| 58 | singleRatio = np.array(singleRatio) |
| 59 | inds = singleRatio.argsort() |
| 60 | sortedLink = singleLink[inds] |
| 61 | sortedFinalList = list(sortedLink[::-1]) |
| 62 | sortedFinalList = sortedFinalList + (4 - len(sortedFinalList)) * [[" "]] |
| 63 | FinalResult.append(singleWrite + sortedFinalList) |
| 64 | else: |
| 65 | sortedFinalList = [[" "]] * 4 |
| 66 | FinalResult.append(singleWrite + sortedFinalList) |
| 67 | |
| 68 |
no test coverage detected