【发布时间】:2016-08-29 12:55:18
【问题描述】:
当我在浏览器中查看页面源代码时,我所追求的 html 会出现在那里。但是,当我使用 python 请求发出请求时,html 不会出现。
我要抓取的网址是http://dota2lounge.com/match?m=13362,而我在页面中追求的特定html是。
<div class="full">
<a class="button" onclick="ChoseEvent(13362,'Whole Match',false)">Match</a>
<a class="button" onclick="ChoseEvent(13392,'1st Game','1462327200')">1st Game</a>
<a class="button" onclick="ChoseEvent(13424,'2nd Game','1462327200')">2nd Game</a>
<br><div id="toma" class="full" style="background: #444;line-height: 2.5rem;border: 1px solid #333;text-align: center;">Whole Match</div>
</div>
我想获取按钮的“onclick”值。到目前为止,我已经尝试过:
r = requests.get('http://dota2lounge.com/match?m=13268')
soup = bs(r.content, 'lxml')
buttons = soup.find_all('a', class_='button')
这不起作用。
r.content
似乎也不显示 html。
【问题讨论】:
-
试试
soup.find_all('a', 'button')。顺便说一句,您在 param 类中有错字:soup.find_all('a', class='button')
标签: python html beautifulsoup python-requests