Advertisement
collinsanele

BING SEARCH (python)

Sep 24th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import time
  4.  
  5.  
  6. headers = {"User-Agent":"Mozilla/5.0 (Linux; Android 7.1.1; Nokia 2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.67 Mobile Safari/537.36"}
  7.  
  8.  
  9. for x in range(1, 4):
  10.     r = requests.get(f"https://bing.com/search?q=Python&first={x}", headers=headers)
  11.  
  12.     soup = BeautifulSoup(r.text, "html.parser")
  13.  
  14.  
  15.     target = soup.find("ol", {"id":"b_results"}).findAll("li", class_="b_algo")
  16.  
  17.  
  18.  
  19.     for item in target:
  20.         try:
  21.             link = item.find("a").get("href")
  22.         except:
  23.             pass
  24.         try:
  25.             title = item.find("h2").text
  26.         except:
  27.             pass
  28.         try:
  29.             body = item.find("div", {"class":"b_caption"}).text
  30.         except:
  31.             pass
  32.        
  33.         if link:
  34.             print(link)
  35.         if title:
  36.             print(title)
  37.         if body:
  38.             print(body)
  39.         print()
  40.         print()
  41.         time.sleep(0.43)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement