Advertisement
cwchen

BeatifulSoup exercise

Apr 9th, 2016
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5. list = [
  6. 'http://engagetheirminds.com/genius-hour-resources/',
  7. 'https://www.google.com/trends/',
  8. ]
  9.  
  10. for a in list:
  11.     links = ['https://www.diigo.com/people/search/url?page=' + str(i+0) + '&query='+a for i in range(1)]
  12.  
  13.     for link in links:
  14.         print link
  15.  
  16.         res = requests.get(link)
  17.         bs_tree = BeautifulSoup(res.text.encode("utf-8"), "html.parser")
  18.         users = bs_tree.select('div.userListUser')
  19.  
  20.         for user in users:
  21.             s = str(user)
  22.             bs_subtree = BeautifulSoup(s, "html.parser")
  23.             user = [u.text for u in bs_subtree.select('h3.userListName a.link2')]
  24.             print user[0]
  25.  
  26.             tags = [a.text for a in bs_subtree.select('div.userListDesc div.userListTags a')]
  27.             print tags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement