首页 > 解决方案 > Python 数据抓取从表中返回空值

问题描述

我正在尝试从网站上抓取数据,但不是使用表中包含的数据打印输出,而是返回一个空字符串。该网站试图从http://tfda.go.tz/portal/registered-products/registered-drug-products-1

这是我用于抓取的代码

from bs4 import BeautifulSoup
import requests
import sys, io
page = requests.get("http://tfda.go.tz/portal/registered-products/registered-drug-products-1")
soup = BeautifulSoup(page.content, 'html.parser')
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,'cp437','backslashreplace')

#print(soup.prettify())

simple = list(soup.children)
#print(simple)

#S/n = ""
Certificate = ""
Brandname = ""
#Classfication Name = ""
#Dosage Form = ""
#Product Strength = ""
Registrant = ""
#Registrant Country = ""
Manufacturer = ""
#Manufacturer Country = ""
#Expiry Date = ""

table = soup.find("table", { "class" :"table table-stripped table_productDrugs" })
print (table)

这是我的输出截图示例输出

我感谢您的帮助

标签: pythonweb-scrapingbeautifulsouppython-requests

解决方案


表中的数据是从动态 xhr http 请求加载的。您应该使用 chrome 检查元素 - 网络 - xhr。您可以找到 xhr 请求。

xhr 获取


推荐阅读