BeautifulSoup4无法通过id选择

时间:2018-03-18 13:04:56

标签: python beautifulsoup

我想获得id='seo_h1_tag'下的Facebook粉丝页面的名称, 但结果是Could not find element

我尝试将seo_h1_tag替换为facebook,这是HTML中的第一个ID并且有效,输出为Element exist。代码有什么问题?

#! python3
import requests,os,bs4
url='https://www.facebook.com/pg/BANDMAIDTW/photos/?tab=album&album_id=1520840718217296'

#Download the page
print('Downloading page %s...' + url)
res = requests.get(url)
res.raise_for_status()
soup=bs4.BeautifulSoup(res.text, "html.parser")

element =soup.select('#seo_h1_tag')
if element==[]:
    print('Could not find element.')
else:
    print('Element exist')

0 个答案:

没有答案
相关问题