I am new to crawling web page. my code is trying to get the time of the website. I found the location and trying to use xpath to get the text(). But my code always return "[]". Did I miss anything?
# -*- coding: utf-8 -*-
import urllib
from bs4 import BeautifulSoup
from lxml import etree
from lxml import html
import requests
headers= { 'User-Agent' : 'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36' }
tree = requests.get('https://www.time.gov/',headers=headers).content#.decode('utf-8')
doc_tree = etree.HTML(tree)
links = doc_tree.xpath('//div[@id="lzTextSizeCache"]/div[@class="lzswftext"]/text()')
print links
The location of the html code is :
<div class="lzswftext" style="padding: 0px; overflow: visible; width: auto; height: auto; font-weight: bold; font-style: normal; font-family: Arial, Verdana; font-size: 50px; white-space: pre; display: none;">09:37:26 a.m. </div>