Advertisement
MeowalsoMeow

web_scraper_stage2

Jun 10th, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import requests
  2. import json
  3. from bs4 import BeautifulSoup
  4.  
  5.  
  6. def check_valid():
  7. url = input("Input the URL:")
  8. r = requests.get(url)
  9. if r:
  10. try:
  11. print(r.json()['content'])
  12. except Exception:
  13. print("Invalid quote resource!")
  14.  
  15. # check_valid()
  16. def check_movie():
  17. r = requests.get(input(), headers={'Accept-Language': 'en-US,en;q=0.5'})
  18. if r:
  19. try:
  20. soup = BeautifulSoup(r.content, 'html.parser')
  21. #title = soup.find('h1', class_='long').get_text()
  22. title = soup.find('div', class_='originalTitle').get_text()
  23. #description = soup.find('div', class_='ipc-html-content ipc-html-content--base').get_text()
  24. summary = soup.find('div', class_='summary_text').get_text()
  25. # print(json.loads(title))
  26. this_dict = {title: summary}
  27. print(this_dict)
  28. except Exception as e:
  29. print("Invalid movie page!", e)
  30.  
  31.  
  32. check_movie()
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement