【发布时间】:2019-08-14 12:19:58
【问题描述】:
我正在尝试解析来自网站https://www.kp.ru/best/kazan/abiturient_2018/ivmit/ 的表格。 Chrome 的 DevTools 向我显示该表是:
<div class="t431__table-wapper" data-auto-correct-mobile-width="false">
<table class="t431__table " style="">
...
</table>
</div>
但是当我这样做时:
url = r"https://www.kp.ru/best/kazan/abiturient_2018/ivmit/"
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
tag = soup.find_all('div', {'class':r't431__table-wapper'})
print(tag)
它返回我就像<table> 是空的:
[<div class="t431__table-wapper" data-auto-correct-mobile-width="false">
<table class="t431__table" style=""></table></div>,
<div class="t431__table-wapper" data-auto-correct-mobile-width="false">
<table class="t431__table" style=""></table></div>,
<div class="t431__table-wapper" data-auto-correct-mobile-width="false">
<table class="t431__table" style=""></table></div>,
<div class="t431__table-wapper" data-auto-correct-mobile-width="false">
<table class="t431__table" style=""></table></div>]
是 JavaScript 还是什么?如何解决这个问题?
【问题讨论】:
-
访问网站。如果它通过 javascript 加载数据,您需要等待整个页面加载完毕,然后才能找到您要查找的表数据。美丽的汤不能这样做。尝试一些成熟的浏览器模拟器 - f.e. Selenium 并等到整个页面加载完毕后再进行抓取。
标签: python parsing web-scraping beautifulsoup screen-scraping