【发布时间】:2022-11-19 22:41:47
【问题描述】:
我问了一个问题并得到了成功的答案(link。不幸的是,我在 google colab 中使用建议的代码时遇到了问题。你能帮我吗(i)让建议的代码在 google colab 中工作;或者(ii)建议我在链接中解释的问题的新代码,好吗?
我正在使用代码:
import requests
import pandas as pd
from bs4 import BeautifulSoup
html = requests.get("https://www.tce.sp.gov.br/jurisprudencia/exibir?proc=18955/989/20&offset=0")
soup = BeautifulSoup(html.content)
data = []
for e in soup.select('table:last-of-type tr:has(td)'):
it = iter(soup.table.stripped_strings)
d = dict(zip(it,it))
d.update({
'link': e.a.get('href'),
'date': e.select('td')[-2].text,
'type': e.select('td')[-1].text
})
data.append(d)
但它返回此错误:
NotImplementedError Traceback (most recent call last)
<ipython-input-14-c9c2af04191b> in <module>
9 data = []
10
---> 11 for e in soup.select('table:last-of-type tr:has(td)'):
12 it = iter(soup.table.stripped_strings)
13 d = dict(zip(it,it))
/usr/local/lib/python3.7/dist-packages/bs4/element.py in select(self, selector, _candidate_generator, limit)
1526 else:
1527 raise NotImplementedError(
-> 1528 'Only the following pseudo-classes are implemented: nth-of-type.')
1529
1530 elif token == '*':
NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.
【问题讨论】:
-
您使用的是什么版本的
beautifulsoup? -
我不知道如何在 colab 中检查它。我知道我的 python 版本是 Python 3.7.15
-
尝试更新您的
beautifulsoup版本,您似乎使用的是旧版本。 -
change python version 也可能确保你安装了
html5lib解析器 [对 bs 和 html 使用!pip show...]
标签: python web-scraping select beautifulsoup google-colaboratory