Beispiel #1
0
 def retrieve_page(self):
     url = "http://weibo.cn/%d/fans" % (self.uid)
     pm = mparameter.Parameter()
     headers = pm.get_headers()
     headers["Cookie"] = COOKIE
     soup = "Flag"
     try:
         response = requests.get(url, headers=headers, timeout=5)
         status = response.status_code
         if status == 200:
             soup = bs4.BeautifulSoup(response.text, "lxml")
         else:
             print("%s error to reach the server %s" % (status, url))
     except Exception:
         print("Error happens! Please check your requests.")
     return soup
Beispiel #2
0
 def retrieve_page(self, cur_page):
     url = self.url % (str((cur_page) * 25))
     pm = mparameter.Parameter()
     headers = pm.get_headers()
     proxies = pm.get_proxies()
     soup = "FLAG"
     try:
         response = requests.get(url, proxies, headers=headers, timeout=5)
         status = response.status_code
         if status == 200:
             soup = bs4.BeautifulSoup(response.text, "lxml")
         else:
             print("%s error to reach the server %s" % (status, url))
     except Exception:
         print("Error happens! Please check your requests.")
     return soup
Beispiel #3
0
 def get_img(self, url, fileloc):
     pm = mparameter.Parameter()
     headers = pm.get_headers()
     proxies = pm.get_proxies()
     try:
         response = requests.get(url, proxies, headers=headers,
                                 timeout=5, stream=True)
         status = response.status_code
         if status == 200:
             with open(fileloc, 'wb') as f:
                 response.raw.decode_content = True
                 shutil.copyfileobj(response.raw, f)
                 for chunk in response.iter_content(1024):
                     f.write(chunk)
         else:
             print("%s error to reach the server %s" % (status, url))
     except Exception:
         print("Error happens! Please check your requests.")