In [1]:
from lxml import html
from lxml import etree
import requests
import time


fo = open("test3.txt", "w")
page = requests.get('https://www.caloriecount.com/exercise')
tree = html.fromstring(page.content)
fl=tree.xpath('//*[@id="content"]/div[1]/div[2]/div[1]/div[2]/ul/li/a/@href')


for i in range(len(fl)):
    fl[i] = "https://www.caloriecount.com"+fl[i]   
    page = requests.get(fl[i])
    tree = html.fromstring(page.content)
    exlinks = tree.xpath('//*[@id="content"]/div[1]/div[3]/ul/li/a/@href')      
    fo.flush()
    #time.sleep(100)
    
    for j in range(len(exlinks)):
        page = requests.get(exlinks[j])
        tree = html.fromstring(page.content)
        print("parsing data from page: "+exlinks[j])

        if tree.xpath('//*[@id="activityitem"]/h1/text()'):
            strn=tree.xpath('//*[@id="activityitem"]/h1/text()')[0]
            strn.replace('Calories burned with ','')
            print(strn,end=', ',file=fo)
        else:
            print("empty record",file=fo)
        
        if tree.xpath('//*[@id="activityitem"]/text()[3]'):
            strn=tree.xpath('//*[@id="activityitem"]/text()[3]')[0]
            strn.replace('/n','')
            print(strn,end='',file=fo)
        else: 
            print("empty record",file=fo)
            
        if tree.xpath('//*[@id="activityitem"]/text()[3]'):
            strn=tree.xpath('//*[@id="activityitem"]/span/text()')[0]
            strn.replace('/n','')
            print(strn,file=fo)
        else: 
            print("empty record",file=fo)
        
fo.close()


parsing data from page: https://www.caloriecount.com/calories-burned-bicycling-a4
parsing data from page: https://www.caloriecount.com/calories-burned-bicycling-a5
parsing data from page: https://www.caloriecount.com/calories-burned-bicycling-a6
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Users\gediz\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, **httplib_request_kw)
    375             try:  # Python 2.7, use buffering of HTTP responses
--> 376                 httplib_response = conn.getresponse(buffering=True)
    377             except TypeError:  # Python 2.6 and older

TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-1-da855e1fd374> in <module>()
     20 
     21     for j in range(len(exlinks)):
---> 22         page = requests.get(exlinks[j])
     23         tree = html.fromstring(page.content)
     24         print("parsing data from page: "+exlinks[j])

C:\Users\gediz\Anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
     65 
     66     kwargs.setdefault('allow_redirects', True)
---> 67     return request('get', url, params=params, **kwargs)
     68 
     69 

C:\Users\gediz\Anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
     51     # cases, and look like a memory leak in others.
     52     with sessions.Session() as session:
---> 53         return session.request(method=method, url=url, **kwargs)
     54 
     55 

C:\Users\gediz\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    466         }
    467         send_kwargs.update(settings)
--> 468         resp = self.send(prep, **send_kwargs)
    469 
    470         return resp

C:\Users\gediz\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
    574 
    575         # Send the request
--> 576         r = adapter.send(request, **kwargs)
    577 
    578         # Total elapsed time of the request (approximately)

C:\Users\gediz\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    374                     decode_content=False,
    375                     retries=self.max_retries,
--> 376                     timeout=timeout
    377                 )
    378 

C:\Users\gediz\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, **response_kw)
    557             httplib_response = self._make_request(conn, method, url,
    558                                                   timeout=timeout_obj,
--> 559                                                   body=body, headers=headers)
    560 
    561             # If we're going to release the connection in ``finally:``, then

C:\Users\gediz\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, **httplib_request_kw)
    376                 httplib_response = conn.getresponse(buffering=True)
    377             except TypeError:  # Python 2.6 and older
--> 378                 httplib_response = conn.getresponse()
    379         except (SocketTimeout, BaseSSLError, SocketError) as e:
    380             self._raise_timeout(err=e, url=url, timeout_value=read_timeout)

C:\Users\gediz\Anaconda3\lib\http\client.py in getresponse(self)
   1172         try:
   1173             try:
-> 1174                 response.begin()
   1175             except ConnectionError:
   1176                 self.close()

C:\Users\gediz\Anaconda3\lib\http\client.py in begin(self)
    280         # read until we get a non-100 response
    281         while True:
--> 282             version, status, reason = self._read_status()
    283             if status != CONTINUE:
    284                 break

C:\Users\gediz\Anaconda3\lib\http\client.py in _read_status(self)
    241 
    242     def _read_status(self):
--> 243         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    244         if len(line) > _MAXLINE:
    245             raise LineTooLong("status line")

C:\Users\gediz\Anaconda3\lib\socket.py in readinto(self, b)
    573         while True:
    574             try:
--> 575                 return self._sock.recv_into(b)
    576             except timeout:
    577                 self._timeout_occurred = True

C:\Users\gediz\Anaconda3\lib\ssl.py in recv_into(self, buffer, nbytes, flags)
    922                   "non-zero flags not allowed in calls to recv_into() on %s" %
    923                   self.__class__)
--> 924             return self.read(nbytes, buffer)
    925         else:
    926             return socket.recv_into(self, buffer, nbytes, flags)

C:\Users\gediz\Anaconda3\lib\ssl.py in read(self, len, buffer)
    784             raise ValueError("Read on closed or unwrapped SSL socket.")
    785         try:
--> 786             return self._sslobj.read(len, buffer)
    787         except SSLError as x:
    788             if x.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs:

C:\Users\gediz\Anaconda3\lib\ssl.py in read(self, len, buffer)
    568         """
    569         if buffer is not None:
--> 570             v = self._sslobj.read(len, buffer)
    571         else:
    572             v = self._sslobj.read(len or 1024)

KeyboardInterrupt: 

In [13]:
fo.flush()
fo.close()

In [ ]: