我试图用BS4从标记中提取一些文本,但每次运行脚本时都会遇到一个TypeError
我试过使用几个不同的解析器,但它们都返回相同的类型错误
我的python代码是:
s = requests.Session()
r = (s.get(url, headers=headers))
soup = BeautifulSoup(r.content, 'html5lib')
profile = soup.find('script', attrs={'name': 'window.profile'})['value']
我想搜集的HTML是:
<script>
// Profile helper.
window.profile = 'PROFILEIDHERE';
</script>
我的代码的预期结果是将'window.profile'的值赋给变量'profile',但每次运行脚本时,我都会得到一个TypeError
可以使用get_text()获取标记的文本值:
相关问题 更多 >
编程相关推荐