Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3.  
  4. r = requests.get("https://www.ghanayello.com/category/hotels/2/city:Kumasi")
  5.  
  6. soup = BeautifulSoup(r.content, "lxml")
  7.  
  8. pages = soup.findAll("a", attrs={"class": "pages_no"})
  9.  
  10. for page in pages:
  11. print(page.a["href"])
  12. # if page.a == None:
  13. # print("None")
  14. # else:
  15. # print(page.a["href"])
  16. # pg
  17. # if pg.a is None:
  18. # print ("1111")
  19. # else:
  20. # print("Test")
  21. tables = soup.findAll("div", attrs={"class": "company"})
  22.  
  23. quotes = []
  24. for row in tables:
  25. quote = {}
  26. link = row.find("a")
  27. if link is None:
  28. print()
  29. else:
  30. quote["name"] = "https://www.ghanayello.com{}".format(row.a["href"])
  31. quotes.append(quote)
  32.  
  33. print(quotes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement