AttributeError:模块“requests”没有属性“get”

0 python

import requests
from bs4 import BeautifulSoup
def spider(max_page):
    page = 1
    while page <= max_page:
        url = 'https://thenewboston.com/forum/recent_activity.php?page=' + str(page)
        source_code = requests.get(url)
        plain_text = source_code.text
        soup = BeautifulSoup(plain_text, "html.parser")
        for link in soup.findAll('a', {'class': 'title text-semibold'}):
            href = link.get('href')
            print(href)
            page += 1
spider(1)


output---------------------------------
C:\Users\Edwardo\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Edwardo/PycharmProjects/pythonJourney/spider.py
Traceback (most recent call last):
  File "C:/Users/Edwardo/PycharmProjects/pythonJourney/spider.py", line 14, in <module>
    spider(1)
  File "C:/Users/Edwardo/PycharmProjects/pythonJourney/spider.py", line 7, in spider
    source_code = requests.get(url)
AttributeError: module 'requests' has no attribute 'get'

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

JRa*_*zor 5

您还有另一个名为“requests”的文件。您需要更改它并重试。

另外,您可以尝试使用pip进行重新安装请求

pip install requests -U
Run Code Online (Sandbox Code Playgroud)