简体   繁体   中英

What is the error in these function and how can i overcome it?

I asked a question and had a successful answer ( link . Unfortunatelly, im having problems while using the suggested code in google colab. Could you help me either (i) getting the suggested code working in google colab; or (ii) suggest a new code for the problem I explained in the link, please?

Im using the code:


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)

But it returns this error:

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.

Your code work perfectly there is no bug at all. Just upgrade "BeautifulSoup".

pip install --upgrade beautifulsoup4

and rest of code will be same.

NOTE: Once you upgrade BeautifulSoup library then restart runtime of your colab environment so that upgraded library come into force.

Step to restart runtime:

Click on Runtime menu.
Select Restart runtime.
Select Run all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM