Advertisement
vinissh

Untitled

Jan 13th, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3.  
  4.  
  5.  
  6. class Noticias(object):
  7.     def __init__(self, url, headers, tags, news, proxxy,cookie):
  8.         self.url = url
  9.         self.tags = tags
  10.         self.headers = headers
  11.         self.news = news
  12.         self.proxxy = proxxy
  13.         self.cookie = cookie
  14.  
  15.     def getUrl(self):
  16.         return self.url
  17.  
  18.     def getHeaders(self):
  19.         return self.headers
  20.  
  21.     def getTags(self):
  22.         return self.tags
  23.  
  24.     def getNews(self):
  25.         return self.news
  26.  
  27.     def getProxxy(self):
  28.         return self.proxxy
  29.  
  30.     def getCookie(self):
  31.       return self.cookie
  32.  
  33.  
  34. url = "https://canaltech.com.br/"
  35. proxies = {
  36.     "http": "http://51.79.84.78:8000",
  37.     "http": "https://391.134.180.0:3128",
  38.  }
  39. headers = {
  40. "authority": "canaltech.com.br",
  41. "method": "GET",
  42. "path": "/mais-lidas/",
  43. "scheme": "https",
  44. "accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
  45. "accept-encoding": "gzip, deflate, br",
  46. "accept-language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
  47. "cookie":" _ga=GA1.3.2109960112.1574971634; OB-USER-TOKEN=c5672179-30c2-4bc7-8315-39c4349025a4; tt.u=830A000A68BD525D8C588AA902BF852B; _ducp=eyJfZHVjcCI6ImY2YTZiOGY4LWY5MTktNDM2Mi04N2Y5LTgxOWJlOTc3YzFhYSIsIl9kdWNwcHQiOiIifQ==; modal-extensao-hide=true; bannertop=premioct2019; __cfduid=d452d6db4354a558bd5442eeadcc147ba1578526069; _gid=GA1.3.761870493.1578925249; tt.nprf=64,68,81,88,24,20,44; _ducprs=eyJMYXN0Q29uc3VsdCI6IjIwMjAtMDEtMTMgMTc6Mjk6NDQiLCJQZXJzb25hQWxpYXMiOm51bGx9; tt_c_vmt=1578946024; tt_c_c=direct; tt_c_s=direct; tt_c_m=direct; _ttuu.s=1578946143403; _gat=1; modal-extensao-pv=43; timelineViewed=343555%2C343555%2C343427%2C343458%2C343427%2C343458%2C54070%2Cfalse; _gat_uolMain=1",
  48. "sec-fetch-mode": "navigate",
  49. "sec-fetch-site": "none",
  50. "sec-fetch-user": "?1",
  51. "upgrade-insecure-requests": "1",
  52. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"}
  53.  
  54. cookie = {
  55.     "OB-USER-TOKEN":"c5672179-30c2-4bc7-8315-39c4349025a4"
  56. }
  57.  
  58. tags = 'teste tags'
  59. news = "novo teste de news"
  60. search = Noticias(url, tags, headers, news, proxxy,cookie)
  61.  
  62.  
  63. try:
  64.   response = requests.post(url, headers=search.getProxxy(),cookies=search.getCookie())
  65.   if response.status_code  == 200:
  66.     soup = BeautifulSoup(response.text,'html.parser')
  67.     print(soup)
  68.    
  69.   else:
  70.     pass
  71. except (requests.exceptions.HTTPError, requests.exceptions.RequestException, requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
  72.         print(str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement