Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import requests
  2. import urllib.request
  3. import urllib.parse
  4. import urllib.error
  5. from bs4 import BeautifulSoup
  6. import ssl
  7. import json
  8.  
  9. url = #instagram url
  10.  
  11. driver = webdriver.Firefox()
  12. driver.get(url)
  13.  
  14.  
  15. for n in range(2):
  16. driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  17. pageSource=driver.page_source
  18. soup = BeautifulSoup(pageSource, 'html.parser')
  19. body = soup.find('body')
  20. script = body.find('script')
  21. raw = script.text.strip().replace('window._sharedData =', '').replace(';', '')
  22.  
  23. json_data=json.loads(raw)
  24. for post in json_data['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges']:
  25. text_src = post['node']['edge_media_to_caption']['edges'][0]['node']['text']
  26. print (text_src)
  27.  
  28. time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement