从网站提取表格 [英] Extracting a table from a website

查看:132
本文介绍了从网站提取表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾多次尝试在此网站检索表格:
是一些东西你应该考虑使用。



这是一个类似的问题,关于 whoscored.com 我以前回答过,您可以使用一个示例工作代码作为出发点:


I've tried many times to retrieve the table at this website: http://www.whoscored.com/Players/845/History/Tomas-Rosicky (the one under "Historical Participations")

import urllib2 
from bs4 import BeautifulSoup 
soup = BeautifulSoup(urllib2.urlopen('http://www.whoscored.com/Players/845/').read())

This is the Python code I am using to retrieve the table html, but I am getting an empty string. Help me out!

解决方案

The desired table is formed via an asynchronous API call to the http://www.whoscored.com/StatisticsFeed/1/GetPlayerStatistics endpoint request to which returns a JSON response. In other words, urllib2 would return you an initial HTML content of the page without the "dynamic" part. In other words, urllib2 is not a browser.

You can study the request using browser developer tools:

Now, you need to simulate this request in your code. requests package is something you should consider using.

Here is a similar question about whoscored.com I've answered before, there is a sample working code you can use as a starting point:

这篇关于从网站提取表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆