我用来从 Tableu 仪表板检索数据的抓取工具坏了。现在,当我尝试抓取任何仪表板时,我都会收到相同的错误:
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
Cell In[1], line 5
3 ts = TS()
4 ts.delayMs = 2000
----> 5 ts.loads(url)
File ~/opt/anaconda3/lib/python3.9/site-packages/tableauscraper/TableauScraper.py:79, in TableauScraper.loads(self, url, params)
76 r = api.getTableauVizForSession(self, self.session, url)
77 soup = BeautifulSoup(r, "html.parser")
---> 79 self.tableauData = json.loads(
80 soup.find("textarea", {"id": "tsConfigContainer"}).text
81 )
83 uri = urlparse(url)
84 self.host = "{uri.scheme}://{uri.netloc}".format(uri=uri)
File ~/opt/anaconda3/lib/python3.9/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
341 s = s.decode(detect_encoding(s), 'surrogatepass')
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:
348 cls = JSONDecoder
File ~/opt/anaconda3/lib/python3.9/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
332 def decode(self, s, _w=WHITESPACE.match):
333 """Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
File ~/opt/anaconda3/lib/python3.9/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
有什么想法吗?这是代码示例:
from tableauscraper import TableauScraper as TS
url = "https://public.tableau.com/views/PlayerStats-Top5Leagues20192020/OnePlayerSummary"
ts = TS()
ts.delayMs = 2000
ts.loads(url)
我尝试使用 Tableuscraper 从 Tableu 仪表板中抓取数据 (https://github.com/bertrandmartel/tableau-scraping)
TableuScraper 期望网站具有 id 为 tsConfigContainer 的 textarea 标记,但给定的 url 没有该标记。因此,代码失败了。
我认为这是 Tableau 中的更改,而 TableauScraper 尚未更新/修复,,
我不确定如何解决该问题,但由于某种原因,响应不是 HTML,而是 JSON。我认为 Tableau 改变了服务器端响应的某些内容,完全破坏了 TableauScraper。