Advertisement
Guest User

beautifulsoup

a guest
Apr 4th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3.  
  4.  
  5. search = input("Enter search term: ")
  6. params = {"q": search}
  7.  
  8. r = requests.get("http://www.bing.com/search")
  9.  
  10. soup = BeautifulSoup(r.text, "html.parser")
  11. results = soup.find("ol", {"id": "b_results"})
  12. links = results.findAll("li", {"class": "b_algo"})
  13.  
  14. for item in links:
  15.     item_text = item.find("a").text
  16.     item_href = item.find("a").attrs["href"]
  17.  
  18.     if item_text and item_href:
  19.         print(item_text)
  20.         print(item_href)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement