是否可以将网站的DOM版本提取到python中?

时间:2019-04-26 16:28:22

标签: python web-scraping beautifulsoup

我想使用BeautifulSoup来解析通过使用urllib.request.urlopen获得的HTML,但是我只是无法获得DOM版本。

我一直在互联网上寻找解决方案,但是我所能找到的只是建议使用soup = BeautifulSoup(rawHTML, 'html.parser')。 无论如何,这并没有为我提供找到特定行所需的DOM代码(如果有帮助,我想使用soup.findAll('img')查找图像。 我确实已经安装了lxml

import urllib.request
from bs4 import BeautifulSoup

siteURL = "https://www.instagram.com/instagram/"
rawHTML = urllib.request.urlopen(siteURL)

soup = BeautifulSoup(rawHTML, 'html.parser')

print(len(soup.findAll('img')))  # prints '0'

我希望获得实际的图像数量,但输出为0。

我也尝试过print(soup.text)print(soup.prettify),并在这些文本中搜索“ img”,但未找到任何内容。

0 个答案:

没有答案