美丽组定位iframe及其属性

2024-09-30 08:29:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我要给iframe src配上漂亮的汤

<div class="divclass">
 <div id="simpleid">
  <iframe width="300" height="300" src="http://google.com>

我可以使用selenium代码:

^{pr2}$

但是硒对这个任务来说太慢了。在

我一直在寻找stackoverflow的解决方案,并尝试了几个代码,但在使用urllib时总是出现错误403(更改浏览器代理不起作用,仍然是403错误),或者我得到“None”


Tags: 代码divsrccomidhttpselenium错误
2条回答

很好的问题。 看看你试图从这个lib中获取iframe的站点,你必须在该div中获取tag的内容,然后用base64对其进行解码,就可以完成了。 看你怎么做事,别停下来!你会成为一个伟大的程序员。在

使用汤。找到所有('要搜索的标签')

>>> from bs4 import BeautifulSoup
>>> html = '''
... <div class="divclass">
...  <div id="simpleid">
...   <iframe width="300" height="300" src="http://google.com">
... '''
>>> soup = BeautifulSoup(html, 'html.parser')
>>> soup.find_all('iframe')
[<iframe height="300" src="http://google.com" width="300">
</iframe>]
>>> soup.find_all('iframe')[0]['src']
u'http://google.com'
>>> 

相关问题 更多 >

    热门问题