【发布时间】:2021-06-19 12:23:01
【问题描述】:
我正在尝试用标签刮掉主表:
<table _ngcontent-jna-c4="" class="rayanDynamicStatement">
来自使用'BeautifulSoup'库的以下网站,但代码返回空[],而打印汤返回html字符串并且请求状态为200。我发现当我使用浏览器'检查元素'工具时,我可以看到表格标签但在“查看页面源代码”中,未显示作为“app-root”标签一部分的表格标签。 (你看到<app-root></app-root> 是空的)。此外,网页组件中没有“json”文件可以从中提取数据。请帮助我如何抓取表格数据。
import urllib.request
import pandas as pd
from urllib.parse import unquote
from bs4 import BeautifulSoup
yurl='https://www.codal.ir/Reports/Decision.aspx?LetterSerial=T1hETjlDjOQQQaQQQfaL0Mb7uucg%3D%3D&rt=0&let=6&ct=0&ft=-1&sheetId=0'
req=urllib.request.urlopen(yurl)
print(req.status)
#get response
response = req.read()
html = response.decode("utf-8")
#make html readable
soup = BeautifulSoup(html, features="html")
table_body=soup.find_all("table")
print(table_body)
【问题讨论】:
-
它是 scrape 不是 scrap。
-
@baduker 是的,你是真的。换了个词。
标签: python python-3.x beautifulsoup