SHARE
TWEET

Untitled

a guest May 21st, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. from bs4 import BeautifulSoup
  3.  
  4.  
  5. def parsepost(post):
  6.     pic_num = 0
  7.     doc_num = 0
  8.     if_poll, if_longread, text_link = None, None, None
  9.     vid_num = 0
  10.     links = []
  11.     views = post['response']['items'][0]['views']['count']
  12.     items = post['response']['items'][0]
  13.     for i in range(len(items['attachments'])):
  14.         if items['attachments'][i]['type'] == 'photo':
  15.             pic_num += 1
  16.         if items['attachments'][i]['type'] == 'video':
  17.             vid_num += 1
  18.         if items['attachments'][i]['type'] == 'link' and 'm.vk.com/@' in items['attachments'][i]['link']['url']:
  19.             if_longread = True
  20.             text_link = items['attachments'][i]['link']['url']
  21.             html = requests.get(text_link).text
  22.             soup = BeautifulSoup(html, 'html.parser').find()
  23.             for k in soup.find_all('a', title=True):
  24.                 links.append(k['title'])
  25.         if items['attachments'][i]['type'] == 'poll':
  26.             if_poll = True
  27.         if items['attachments'][i]['type'] == 'doc':
  28.             doc_num += 1
  29.     return{"pic_num" : pic_num, "doc_num" : doc_num, "vid_num" : vid_num, "if_poll" : if_poll, "if_longread" : if_longread, "links" : links, 'views' : views}
  30.  
  31. def parsedoc():
  32.     pass
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top