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
Asked
Active
Viewed 2.0k times
0

JRazor
- 2,707
- 18
- 27

Edward Alex
- 7
- 1
- 1
- 2
-
after doing some searching for this problem, it seems likely to pop up when you have either another script named `requests.py` sitting in your current directory or in your Python path. – n1c9 Apr 09 '16 at 20:40
-
What's the output of `dir(requests)`? – jDo Apr 09 '16 at 21:36
-
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__'] – Edward Alex Apr 11 '16 at 21:39
1 Answers
5
You have another file with this name "requests". You need change it and try again.
Also, you can try to use pip for reinstall requests:
pip install requests -U

JRazor
- 2,707
- 18
- 27
-
-
my previous python programs work very fine with requests.get but now all those program give me error AttributeError: module 'requests' has no attribute 'get' – Edward Alex Apr 09 '16 at 21:24
-
@EdwardAlex, this problem has two variants: 1) you have another script with this name. 2) you have bad standart library request. Try find another script or use **pip install requests -U** – JRazor Apr 09 '16 at 21:30
-
-
-
I am having the same issue. No other "requests" file on my system. If I uninstall requests and reinstall it, I can import requests one time at the Python3.7 prompt, but then it will error if I exit and try again. One thing I do notice is that a __pycache__ file is created. – Calab Oct 10 '19 at 22:09
-
1@Calab Probably, u have another file with same name (like requests.py). Check out – JRazor Oct 12 '19 at 06:00
-