collinsanele

Untitled

May 21st, 2020
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def scrape_nairaland():
  2.     headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"}
  3.     r = requests.get("https://nairaland.com", headers=headers)
  4.     soup = BeautifulSoup(r.content, "html.parser")
  5.     links = [item.get("href") for item in soup.find("td", class_="featured").find_all("a")][:65]
  6.     links_text = [item.text for item in soup.find("td", class_="featured").find_all("a")][:65]
  7.    
  8.     return {
  9.        
  10.                 "links_data":zip(links_text, links)
  11.                
  12.        
  13.             }
Advertisement
Add Comment
Please, Sign In to add comment