|  | 
 
| 
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  为了做我的游戏, 方便起见上网上用requests来获取一下
 代码:
 
 
 
 复制代码import requests
from bs4 import BeautifulSoup
def get_pokemon_info():
    url = 'https://wiki.52poke.com/wiki/%E5%AE%9D%E5%8F%AF%E6%A2%A6%E5%88%97%E8%A1%A8%EF%BC%88%E6%8C%89%E5%85%B3%E9%83%BD%E5%9B%BE%E9%89%B4%E7%BC%96%E5%8F%B7%EF%BC%89'
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')
    # 找到宝可梦列表的表格
    pokemon_table = soup.find('table', {'class': 'sortable'})
    # 解析表格中的每一行数据
    pokemon_rows = pokemon_table.find_all('tr')
    pokemon_data = {}
    for row in pokemon_rows[1:]:  # 跳过标题行
        cells = row.find_all('td')
        if not cells:
            continue
        # 获取宝可梦的编号、名字、属性、HP、攻击、防御、速度等信息
        num = cells[0].text.strip()
        name = cells[1].text.strip()
        types = [type.text.strip() for type in cells[2].find_all('a')]
        hp = int(cells[3].text.strip())
        attack = int(cells[4].text.strip())
        defense = int(cells[5].text.strip())
        speed = int(cells[6].text.strip())
        # 存储宝可梦数据
        pokemon_data[num] = {
            '名字': name,
            '属性': types,
            'HP': hp,
            '攻击': attack,
            '防御': defense,
            '速度': speed
        }
    return pokemon_data
# 调用函数并打印结果
pokemon_info = get_pokemon_info()
for num, info in pokemon_info.items():
    print(f"{num}: {info}")
错误:
 
 复制代码Traceback (most recent call last):
  File "D:/Python projects/3项目/读取2.py", line 1, in <module>
    import requests
  File "C:\Users\33090\AppData\Roaming\Python\Python312\site-packages\requests\__init__.py", line 64, in <module>
    from . import utils
  File "C:\Users\33090\AppData\Roaming\Python\Python312\site-packages\requests\utils.py", line 29, in <module>
    from .structures import CaseInsensitiveDict
  File "C:\Users\33090\AppData\Roaming\Python\Python312\site-packages\requests\structures.py", line 16, in <module>
    class CaseInsensitiveDict(collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
把requests里的cookies.py的
 
 class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):改成了
 
 复制代码class RequestsCookieJar(cookielib.CookieJar, collections.abc.MutableMapping):
依然不好使
 求助
      | 
 |