本文整理汇总了Python中pycurl.COOKIEFILE属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.COOKIEFILE属性的具体用法?Python pycurl.COOKIEFILE怎么用?Python pycurl.COOKIEFILE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pycurl
的用法示例。
在下文中一共展示了pycurl.COOKIEFILE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_curl
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def generate_curl(self, url=None, headers=None):
""" 生成一个curl, 返回 curl 实例和用于获取结果的 buffer
"""
curl = pycurl.Curl()
buff = StringIO()
curl.setopt(pycurl.COOKIEFILE, "cookie")
curl.setopt(pycurl.COOKIEJAR, "cookie_jar")
curl.setopt(pycurl.SHARE, self.http._share)
curl.setopt(pycurl.WRITEFUNCTION, buff.write)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.TIMEOUT, 3)
curl.setopt(pycurl.CONNECTTIMEOUT, 3)
if url:
curl.setopt(pycurl.URL, url)
if headers:
self.set_curl_headers(curl, headers)
return curl, buff
示例2: fetch_url
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def fetch_url(self, url, **kwargs):
filename = kwargs.get('filename', self.filename)
self.fix()
cookiefile = tempfile.NamedTemporaryFile(suffix='.txt')
f = open(os.path.join(self.directory, filename), 'wb')
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.WRITEDATA, f)
c.setopt(pycurl.USERAGENT, 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36')
c.setopt(pycurl.COOKIEFILE, cookiefile.name)
c.perform()
c.close()
cookiefile.close()
self.save()
return
示例3: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def request(self, endpoint, headers=None, post=None, first=True):
buffer = BytesIO()
ch = pycurl.Curl()
ch.setopt(pycurl.URL, endpoint)
ch.setopt(pycurl.USERAGENT, self.userAgent)
ch.setopt(pycurl.WRITEFUNCTION, buffer.write)
ch.setopt(pycurl.FOLLOWLOCATION, True)
ch.setopt(pycurl.HEADER, True)
if headers:
ch.setopt(pycurl.HTTPHEADER, headers)
ch.setopt(pycurl.VERBOSE, self.debug)
ch.setopt(pycurl.SSL_VERIFYPEER, False)
ch.setopt(pycurl.SSL_VERIFYHOST, False)
ch.setopt(pycurl.COOKIEFILE, self.settingsPath + self.username + '-cookies.dat')
ch.setopt(pycurl.COOKIEJAR, self.settingsPath + self.username + '-cookies.dat')
if post:
import urllib
ch.setopt(pycurl.POST, len(post))
ch.setopt(pycurl.POSTFIELDS, urllib.urlencode(post))
ch.perform()
resp = buffer.getvalue()
header_len = ch.getinfo(pycurl.HEADER_SIZE)
header = resp[0: header_len]
body = resp[header_len:]
ch.close()
if self.debug:
import urllib
print("REQUEST: " + endpoint)
if post is not None:
if not isinstance(post, list):
print('DATA: ' + urllib.unquote_plus(json.dumps(post)))
print("RESPONSE: " + body + "\n")
return [header, json_decode(body)]
示例4: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def request(self, endpoint, post=None):
buffer = BytesIO()
ch = pycurl.Curl()
ch.setopt(pycurl.URL, Constants.API_URL + endpoint)
ch.setopt(pycurl.USERAGENT, self.userAgent)
ch.setopt(pycurl.WRITEFUNCTION, buffer.write)
ch.setopt(pycurl.FOLLOWLOCATION, True)
ch.setopt(pycurl.HEADER, True)
ch.setopt(pycurl.VERBOSE, False)
ch.setopt(pycurl.COOKIEFILE, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat"))
ch.setopt(pycurl.COOKIEJAR, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat"))
if post is not None:
ch.setopt(pycurl.POST, True)
ch.setopt(pycurl.POSTFIELDS, post)
if self.proxy:
ch.setopt(pycurl.PROXY, self.proxyHost)
if self.proxyAuth:
ch.setopt(pycurl.PROXYUSERPWD, self.proxyAuth)
ch.perform()
resp = buffer.getvalue()
header_len = ch.getinfo(pycurl.HEADER_SIZE)
header = resp[0: header_len]
body = resp[header_len:]
ch.close()
if self.debug:
print("REQUEST: " + endpoint)
if post is not None:
if not isinstance(post, list):
print("DATA: " + str(post))
print("RESPONSE: " + body)
return [header, json_decode(body)]
示例5: get
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def get(url, encoding, user_agent=UA, referrer=None):
"""Make a GET request of the url using pycurl and return the data
(which is None if unsuccessful)"""
data = None
databuffer = BytesIO()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 5)
curl.setopt(pycurl.TIMEOUT, 8)
curl.setopt(pycurl.WRITEDATA, databuffer)
curl.setopt(pycurl.COOKIEFILE, '')
if user_agent:
curl.setopt(pycurl.USERAGENT, user_agent)
if referrer is not None:
curl.setopt(pycurl.REFERER, referrer)
try:
curl.perform()
data = databuffer.getvalue().decode(encoding)
except Exception:
pass
curl.close()
return data
示例6: get_url
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def get_url (url, user_agent=UA, referrer=None):
"""Make a GET request of the url using pycurl and return the data
(which is None if unsuccessful)"""
data = None
databuffer = StringIO()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 5)
curl.setopt(pycurl.TIMEOUT, 8)
curl.setopt(pycurl.WRITEFUNCTION, databuffer.write)
curl.setopt(pycurl.COOKIEFILE, '')
if user_agent:
curl.setopt(pycurl.USERAGENT, user_agent)
if referrer is not None:
curl.setopt(pycurl.REFERER, referrer)
try:
curl.perform()
data = databuffer.getvalue()
except Exception:
pass
curl.close()
return data
示例7: setup_curl
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def setup_curl(self):
_curls = []
for curl in self._curls:
curl.setopt(pycurl.SHARE, self._share)
if self.use_cookie:
curl.setopt(pycurl.COOKIEFILE, "cookie")
curl.setopt(pycurl.COOKIEJAR, "cookie_jar")
_curls.append(curl)
self._curls = _curls
示例8: from_url
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def from_url(self, url):
"""Makes the contents of the file the contents of the given URL."""
self.retrieve()
cookiefile = tempfile.NamedTemporaryFile(suffix='.txt')
the_path = self.file_info['path']
f = open(the_path, 'wb')
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.WRITEDATA, f)
c.setopt(pycurl.USERAGENT, docassemble.base.functions.server.daconfig.get('user agent', 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36'))
c.setopt(pycurl.COOKIEFILE, cookiefile.name)
c.perform()
c.close()
self.retrieve()
示例9: __init__
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def __init__(self, base_url="", fakeheaders=[]):
self.handle = pycurl.Curl()
# These members might be set.
self.set_url(base_url)
self.verbosity = 0
self.fakeheaders = fakeheaders
# Nothing past here should be modified by the caller.
self.payload = None
self.payload_io = BytesIO()
self.hrd = ""
# Verify that we've got the right site; harmless on a non-SSL connect.
self.set_option(pycurl.SSL_VERIFYHOST, 2)
# Follow redirects in case it wants to take us to a CGI...
self.set_option(pycurl.FOLLOWLOCATION, 1)
self.set_option(pycurl.MAXREDIRS, 5)
self.set_option(pycurl.NOSIGNAL, 1)
# Setting this option with even a nonexistent file makes libcurl
# handle cookie capture and playback automatically.
self.set_option(pycurl.COOKIEFILE, "/dev/null")
# Set timeouts to avoid hanging too long
self.set_timeout(30)
# Use password identification from .netrc automatically
self.set_option(pycurl.NETRC, 1)
self.set_option(pycurl.WRITEFUNCTION, self.payload_io.write)
def header_callback(x):
self.hdr += x.decode('ascii')
self.set_option(pycurl.HEADERFUNCTION, header_callback)
示例10: init_pycurl
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def init_pycurl(debug=False):
"""
Provides an instances of pycurl with basic configuration
:return: pycurl instance
"""
_curl = pycurl.Curl()
_curl.setopt(pycurl.SSL_OPTIONS, pycurl.SSLVERSION_TLSv1_2)
_curl.setopt(pycurl.SSL_VERIFYPEER, False)
_curl.setopt(pycurl.SSL_VERIFYHOST, False)
_curl.setopt(pycurl.VERBOSE, debug)
_curl.setopt(pycurl.TIMEOUT, 10)
_curl.setopt(pycurl.COOKIEFILE, "")
_curl.setopt(pycurl.USERAGENT, 'APIFuzzer')
return _curl
示例11: get
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def get(self,
url,
header=None,
proxy_host=None,
proxy_port=None,
cookie_file=None):
'''
open url width get method
@param url: the url to visit
@param header: the http header
@param proxy_host: the proxy host name
@param proxy_port: the proxy port
'''
crl = pycurl.Curl()
#crl.setopt(pycurl.VERBOSE,1)
crl.setopt(pycurl.NOSIGNAL, 1)
# set proxy
# crl.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
rel_proxy_host = proxy_host or self.proxy_host
if rel_proxy_host:
crl.setopt(pycurl.PROXY, rel_proxy_host)
rel_proxy_port = proxy_port or self.proxy_port
if rel_proxy_port:
crl.setopt(pycurl.PROXYPORT, rel_proxy_port)
# set cookie
rel_cookie_file = cookie_file or self.cookie_file
if rel_cookie_file:
crl.setopt(pycurl.COOKIEFILE, rel_cookie_file)
crl.setopt(pycurl.COOKIEJAR, rel_cookie_file)
# set ssl
crl.setopt(pycurl.SSL_VERIFYPEER, 0)
crl.setopt(pycurl.SSL_VERIFYHOST, 0)
crl.setopt(pycurl.SSLVERSION, 3)
crl.setopt(pycurl.CONNECTTIMEOUT, 10)
crl.setopt(pycurl.TIMEOUT, 300)
crl.setopt(pycurl.HTTPPROXYTUNNEL, 1)
rel_header = header or self.header
if rel_header:
crl.setopt(pycurl.HTTPHEADER, rel_header)
crl.fp = StringIO.StringIO()
if isinstance(url, unicode):
url = str(url)
crl.setopt(pycurl.URL, url)
crl.setopt(crl.WRITEFUNCTION, crl.fp.write)
try:
crl.perform()
except Exception, e:
raise CurlException(e)
示例12: post
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def post(self,
url,
data,
header=None,
proxy_host=None,
proxy_port=None,
cookie_file=None):
'''
open url width post method
@param url: the url to visit
@param data: the data to post
@param header: the http header
@param proxy_host: the proxy host name
@param proxy_port: the proxy port
'''
crl = pycurl.Curl()
#crl.setopt(pycurl.VERBOSE,1)
crl.setopt(pycurl.NOSIGNAL, 1)
# set proxy
rel_proxy_host = proxy_host or self.proxy_host
if rel_proxy_host:
crl.setopt(pycurl.PROXY, rel_proxy_host)
rel_proxy_port = proxy_port or self.proxy_port
if rel_proxy_port:
crl.setopt(pycurl.PROXYPORT, rel_proxy_port)
# set cookie
rel_cookie_file = cookie_file or self.cookie_file
if rel_cookie_file:
crl.setopt(pycurl.COOKIEFILE, rel_cookie_file)
crl.setopt(pycurl.COOKIEJAR, rel_cookie_file)
# set ssl
crl.setopt(pycurl.SSL_VERIFYPEER, 0)
crl.setopt(pycurl.SSL_VERIFYHOST, 0)
crl.setopt(pycurl.SSLVERSION, 3)
crl.setopt(pycurl.CONNECTTIMEOUT, 10)
crl.setopt(pycurl.TIMEOUT, 300)
crl.setopt(pycurl.HTTPPROXYTUNNEL, 1)
rel_header = header or self.header
if rel_header:
crl.setopt(pycurl.HTTPHEADER, rel_header)
crl.fp = StringIO.StringIO()
crl.setopt(crl.POSTFIELDS, data) # post data
if isinstance(url, unicode):
url = str(url)
crl.setopt(pycurl.URL, url)
crl.setopt(crl.WRITEFUNCTION, crl.fp.write)
try:
crl.perform()
except Exception, e:
raise CurlException(e)
示例13: upload
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import COOKIEFILE [as 别名]
def upload(self,
url,
data,
header=None,
proxy_host=None,
proxy_port=None,
cookie_file=None):
'''
open url with upload
@param url: the url to visit
@param data: the data to upload
@param header: the http header
@param proxy_host: the proxy host name
@param proxy_port: the proxy port
'''
crl = pycurl.Curl()
#crl.setopt(pycurl.VERBOSE,1)
crl.setopt(pycurl.NOSIGNAL, 1)
# set proxy
rel_proxy_host = proxy_host or self.proxy_host
if rel_proxy_host:
crl.setopt(pycurl.PROXY, rel_proxy_host)
rel_proxy_port = proxy_port or self.proxy_port
if rel_proxy_port:
crl.setopt(pycurl.PROXYPORT, rel_proxy_port)
# set cookie
rel_cookie_file = cookie_file or self.cookie_file
if rel_cookie_file:
crl.setopt(pycurl.COOKIEFILE, rel_cookie_file)
crl.setopt(pycurl.COOKIEJAR, rel_cookie_file)
# set ssl
crl.setopt(pycurl.SSL_VERIFYPEER, 0)
crl.setopt(pycurl.SSL_VERIFYHOST, 0)
crl.setopt(pycurl.SSLVERSION, 3)
crl.setopt(pycurl.CONNECTTIMEOUT, 10)
crl.setopt(pycurl.TIMEOUT, 300)
crl.setopt(pycurl.HTTPPROXYTUNNEL, 1)
rel_header = header or self.header
if rel_header:
crl.setopt(pycurl.HTTPHEADER, rel_header)
crl.fp = StringIO.StringIO()
if isinstance(url, unicode):
url = str(url)
crl.setopt(pycurl.URL, url)
crl.setopt(pycurl.HTTPPOST, data) # upload file
crl.setopt(crl.WRITEFUNCTION, crl.fp.write)
try:
crl.perform()
except Exception, e:
raise CurlException(e)