use http2.py instead of requests
This commit is contained in:
23
ppf.py
23
ppf.py
@@ -1,17 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import requests
|
||||
import random, time
|
||||
import re
|
||||
import urllib
|
||||
import hashlib
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
import mysqlite
|
||||
import proxywatchd
|
||||
from misc import _log
|
||||
from soup_parser import soupify
|
||||
import config
|
||||
from http2 import RsHttp, _parse_url
|
||||
import rocksock
|
||||
|
||||
base_header = {
|
||||
'Accept-Language':'en-US,en;q=0.8',
|
||||
@@ -40,17 +39,18 @@ def import_from_file(fn, sqlite):
|
||||
sqlite.execute('INSERT INTO uris (added,url,check_time,error) VALUES (?,?,?,?)', (time.time(),u,0,1))
|
||||
sqlite.commit()
|
||||
|
||||
def fetch_contents(uri):
|
||||
def fetch_contents(url):
|
||||
headers = base_header
|
||||
try: resp = requests.get(uri, timeout=45, headers=headers, verify=False, proxies=proxies)
|
||||
except KeyboardInterrupt as e: raise e
|
||||
except: return ''
|
||||
data = resp.text
|
||||
|
||||
host, port, ssl, uri = _parse_url(url)
|
||||
proxies = [rocksock.RocksockProxyFromURL('socks4://%s' % random.choice( config.torhosts ))]
|
||||
http = RsHttp(host,ssl=ssl,port=port, keep_alive=True, follow_redirects=True, auto_set_cookies=True, proxies=proxies, user_agent="curl/7.60.0")
|
||||
if not http.connect(): return ''
|
||||
hdr, res = http.get(uri)
|
||||
res = res.encode('utf-8') if isinstance(res, unicode) else res
|
||||
for retry_message in retry_messages:
|
||||
if retry_message in data: return ''
|
||||
if retry_message in res: return ''
|
||||
|
||||
return data
|
||||
return res
|
||||
|
||||
def insert_proxies(proxies, uri, sqlite):
|
||||
time_now = time.time()
|
||||
@@ -169,6 +169,7 @@ if __name__ == '__main__':
|
||||
else:
|
||||
watcherd = None
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
## any site that needs to be checked ?
|
||||
|
||||
Reference in New Issue
Block a user