【问题标题】:Python BeautifulSoup web scraping: Why section tag is not showing anything inside it?Python BeautifulSoup 网页抓取:为什么部分标签内部没有显示任何内容?
【发布时间】:2018-04-22 15:10:16
【问题描述】:

我正在尝试以下代码,但在 section 标记中没有得到任何内容

page = requests.get('https://www.iplt20.com/match/2018/20?tab=scorecard')
soup = BeautifulSoup(page.content, 'html.parser')
soup.find_all('section', {'class':'contentTab tab3 scorecardContent'})

我得到以下结果:
[<section class="contentTab tab3 scorecardContent" id="scorecardContent" style="display:none"></section>]

下面是部分标签:

我检查并发现我想要的内容/文本在innerText 但我无法获取它

请帮忙,我怎样才能得到innerText中显示的详细信息?

【问题讨论】:

  • 直接查询this API即可得到结果。
  • 是的,我可以,但我想自己做。谢谢@KeyurPotdar

标签: python python-3.x web-scraping beautifulsoup


【解决方案1】:

您可以使用RequestsHTML

代码:

from requests_html import HTMLSession

session = HTMLSession()
r = session.get('https://www.iplt20.com/match/2018/20?tab=scorecard')
r.html.render()

tab3 = r.html.find('#scorecardContent', first=True)
print(tab3.text)

输出:

Sunrisers Hyderabad Innings (Run Rate: 8.90)
Batsmen
Runs
...

【讨论】:

    猜你喜欢
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多