【发布时间】:2020-08-11 09:39:49
【问题描述】:
下面是需要提取的HTML代码
<div class="one_block" style="display:block;" onClick="location.href=\'/games/box.html
?&game_type=01&game_id=13&game_date=2020-04-19&pbyear=2020\';" style="cursor:pointer;">
<!-- \xe5\xb0\x8d\xe6\x88\xb0\xe7\x90\x83\xe9\x9a\x8
a\xe5\x8f\x8a\xe5\xa0\xb4\xe5\x9c\xb0 start -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="schedule_team">
<tr>
如何获得location.href 值?
试过了:
soup.findAll("div", {"onClick": "location.href"})
返回null
Desired Output:
/games/box.html?&game_type=01&game_id=13&game_date=2020-04-19&pbyear=2020
PS:有很多
location.href
【问题讨论】:
-
嗨,你试过正则表达式吗? import re from bs4 import BeautifulSoup soup.find_all('a', {'onClick': re.compile(r'location.href')})
-
不,但为什么是
regex?我觉得regex占用了更多时间 -
这只是一个建议...也许您可以尝试一下并使用分析器来跟踪性能问题
-
什么没用?你仍然得到 None ?或者你有错误?
-
@johnrao07 想要的输出是什么?
标签: python html beautifulsoup