1.问题:写好了代码,抓取网页上某标签的文本内容时,抓取结果为空白,查看网页源代码发现该标签文本内容存在。源代码如下。
import requests
from bs4 import BeautifulSoup
response = requests.get('https://ncov.dxy.cn/ncovh5/view/pneumonia')
home_page = response.content.decode()
soup = BeautifulSoup(home_page, 'lxml')
script = soup.find(id='getListByCountryTypeService2true')
text = script.text
print(text)
2.运行结果:空白
3.尝试过加上头(headers),无效。
望大佬们不吝赐教,最好有完整代码!跪谢!!!