【发布时间】:2019-07-30 01:27:03
【问题描述】:
我尝试在按钮标签内刮出一个 ImageId,想要得到结果:
"25511e1fd64e99acd991a22d6c2d6b6c".
当我尝试时:
drawing_url = drawing_url.find_all('button', class_='inspectBut')['onclick']
它不起作用。报错-
TypeError: list indices must be integers or slices, not str
输入 =
for article in soup.find_all('div', class_='dojoxGridRow'):
drawing_url = article.find('td', class_='dojoxGridCell', idx='3')
drawing_url = drawing_url.find_all('button', class_='inspectBut')
if drawing_url:
for e in drawing_url:
print(e)
输出 =
<button class="inspectBut" href="#"
onclick="window.open('getImg?imageId=25511e1fd64e99acd991a22d6c2d6b6c&
timestamp=1552011572288','_blank', 'toolbar=0,
menubar=0, modal=yes, scrollbars=1, resizable=1,
height='+$(window).height()+', width='+$(window).width())"
title="Open Image" type="button">
</button>
...
...
【问题讨论】:
-
我不是专家,但
[onclick]不应该是['onclick'] -
抱歉错字我实际上输入了 ['onclick'],它给出了错误:drawing_url = drawing_url.find_all('button', class_='inspectBut')['onclick'] TypeError: list indices must be整数或切片,而不是 str
-
提供 url/足够的源 html 有助于获得质量更好的答案,并可能更快地解决问题。
标签: python web-scraping beautifulsoup python-requests