Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import request
  2. from datetime import date
  3. import bs4
  4.  
  5.  
  6. def checkNeg(s):
  7. for i in range(len(s)):
  8. if s[i]=='-':
  9. return -1
  10. pagenum = 0
  11. ques = []
  12. link = []
  13. votes= []
  14. over = 0
  15.  
  16. while pagenum<1000:
  17. pagenum = pagenum + 1
  18. pageurl = "https://stackoverflow.com/search?page="+str(pagenum)+ "&tab=Newest&q=android%20features"
  19. res = requests.get(pageurl) #Data from Stack Overflow
  20.  
  21. soup = bs4.BeautifulSoup(res.text, 'html.parser') #Building a lxml file from res.text
  22. #building the question and hyperlink arrays
  23. Count = 0
  24. question_ref = soup.select('.question-hyperlink')
  25. vote_ref = soup.select('.vote')
  26. time_ref = soup.select('.relativetime')
  27. # print(len(question_ref))
  28. # print(len(vote_ref))
  29. for i in range(0,15):
  30. # print(i)
  31. qu = (question_ref[i].text)
  32. ques.append(qu.lstrip())
  33. link.append("https://www.stackoverflow.com"+question_ref[i].get('href'))
  34. strin = (vote_ref[i].text)
  35. if checkNeg(strin):
  36. votes.append(-1)
  37. else:
  38. vote = [int(s) for s in strin.split() if s.isdigit()]
  39. votes.append(vote[0])
  40. times = time_ref[i].text
  41. print(times)
  42. if "Dec" in times:
  43. if int(times[4:])<=6:
  44. over = 1
  45. break
  46.  
  47. if over == 1:
  48. break
  49.  
  50. time.sleep(1)
  51. most_recent_data = ques[:10]
  52. most_recent_link = link[:10]
  53.  
  54. for i in range(len(votes)):
  55. for j in range(len(votes)-1):
  56. if votes[j]<votes[j+1]:
  57. votes[j],votes[j+1]=votes[j+1],votes[j]
  58. ques[j],ques[j+1] = ques[j+1],ques[j]
  59. link[j],link[j+1]=link[j+1],link[j]
  60.  
  61. top_voted_ques = ques[:10]
  62. top_voted_link = link[:10]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement