Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用javascript检索的表内容来抓取网站?_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 如何使用javascript检索的表内容来抓取网站?

Python 如何使用javascript检索的表内容来抓取网站?,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我想从一个网站上抓取一张像这样的桌子 <table class="table table-hover data-table sort display"> <thead> <tr> <th class="Column1"> </th> <th class="Column2"> </th>

我想从一个网站上抓取一张像这样的桌子

<table class="table table-hover data-table sort display">
        <thead>
          <tr>
            <th class="Column1">
            </th>
            <th class="Column2">
            </th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="item in filteredList | orderBy:columnToOrder:reverse">
            <td>{{item.Col1}}</td>
            <td>{{item.Col2}}</td>
          </tr>
        </tbody>
</table>

{{item.Col1}}
{{item.Col2}}
这个网站似乎是使用一些javascript框架构建的,该框架通过web服务从后端检索表内容

问题是,如果数据不是数字格式,我们如何刮取表数据?上面的代码包含在
{}
中的内容。这会使网站变得不可拆分吗?有解决办法吗?多谢各位


我正在使用python和beautifulsoup4。

通常当有JS内容时,BeautifulSoup不是工具。我用硒。尝试此操作,查看您获得的HTML是否可刮取:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get(url)
driver.set_window_position(0, 0)
driver.set_window_size(100000, 200000)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(5) # wait to load

# now print the response
print driver.page_source

此时,您可以使用BeautifulSoup从
驱动程序.page\u source
中提取数据。注意:您需要安装selenium和Firefox,您可以尝试使用import.io()-我们的连接器、提取器和爬虫程序都支持从使用JavaScript呈现的页面获取数据。如果没有一个特定的URL,我无法确定你的URL是否能正常工作,但我不明白为什么不能(看起来它是由AngularJS呈现的,应该可以)


p、 如果你还没有弄明白,我在import.io工作-如果你有具体问题,给我写封信。

你能做的就是转到Chrome,加载网站。转到控制台并转到“网络”选项卡。在顶部勾选“保存日志”。重新加载站点并加载日志中的所有内容。现在,您将在页面上看到“filteredList”的数据来源。所以在你的刮板中,你现在也知道数据来自哪里,所以你可以把它包括在你的刮板中。数据很可能是json格式的。。。你可以把它捡起来,摆弄得心满意足