我无法使用BeautifulSoup找到元素?

时间:2018-07-05 19:25:36

标签: python beautifulsoup

我正试图使机器人抓取此页面http://www.skysports.com/transfer-centre,当我在Chrome中打开该页面时,可以在开发人员工具中看到我想要的元素

element

但是当我使用下面的代码时,它返回None:

import requests
from bs4 import BeautifulSoup

page = requests.get('http://www.skysports.com/transfer-centre').text
soup = BeautifulSoup(page, 'lxml')
print(soup.find('time'))

我想念什么吗?

1 个答案:

答案 0 :(得分:1)

用于从提供的网址中提取时间, https://data.livefyre.com/bs3/v3.1/bskyb.fyre.co/363166/MTAwMDk1MTI=/init 我来自http://www.skysports.com/transfer-centre

的网址
import requests
import time
import json

page = requests.get('https://data.livefyre.com/bs3/v3.1/bskyb.fyre.co/363166/MTAwMDk1MTI=/init').json()
contents = page['headDocument']['content']
for content in contents:
    c = content['content']
    t = c['updatedAt']
    tt = time.strftime('%H:%M', time.localtime(t))
    authorId = c['authorId']
    bodyHtml = c['bodyHtml']
    print('time : {} , auther: {}'.format(tt, authorId))
    print('------------')
    print('bodyHtml: {}' , json.dumps(bodyHtml, None, 4))
    print('-----------\n\n')