【问题标题】:Web scraping with Python, but values are empty使用 Python 进行网页抓取,但值为空
【发布时间】:2013-06-10 20:26:49
【问题描述】:

我想使用 BeautifulSoup 从该站点获取值:http://cdn.ime-co.ir/,但是当我尝试导入表时值是空的。我认为用 javascrip 或任何我不知道的东西禁用。 请帮我将值导出为 csv 或 txt 格式。

import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://cdn.ime-co.ir/').read())
print soup

【问题讨论】:

  • >>> 导入 urllib2 >>> 从 bs4 导入 BeautifulSoup >>> 汤 = BeautifulSoup(urllib2.urlopen('cdn.ime-co.ir/').read()) >>> 打印汤

标签: javascript python web-scraping beautifulsoup screen-scraping


【解决方案1】:

BeautifulSoup 不支持 Javascript。如果您只需要解析它一次,您显然可以将源代码保存到文件并从那里解析。如果您需要多次获取该站点,可以考虑使用 Webkit (here's an example using PyQT4 with Webkit) 或 PhantomJS 生成可以在 Python 中解析的源代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 2020-10-04
    • 2021-05-08
    • 2018-07-20
    • 2021-01-13
    • 2020-03-13
    相关资源
    最近更新 更多