A trouble with requests - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: A trouble with requests (/thread-16380.html) |
A trouble with requests - Truman - Feb-25-2019 # The following will return a list of 2-grams found in the Wikipedia article on the Python programming language: import requests from bs4 import BeautifulSoup def getNgrams(input, n): input = input.split('') output = [] for i in range(len(input)-n+1): output.append(input[i:i+n]) return output html = requests.get("https://en.wikipedia.org/wiki/Python_(programming_language)") bsObj = BeautifulSoup(html.content, 'html.parser') content = bsObj.find("div", {"id":"mw-content-text"}).get_text() ngrams = getNgrams(content, 2) print(ngrams) print("2-grams count is: "+str(len(ngrams))) Any idea why these errors appear?
RE: A trouble with requests - Larz60+ - Feb-25-2019 something funky going on. You shouldn't have any problem importing requests unless something trashed memory. try opening an interactive python and simply importing requests RE: A trouble with requests - Truman - Feb-26-2019 Do you mean in IDLE? It doesn't give anything. RE: A trouble with requests - Larz60+ - Feb-26-2019 I didn't mean idle, I meant to start python from command line or bash shell by typing python, but IDLE will do. So if you don't get any message from 'IDLE' then something else is causing requests to fail on import in your new program. If you're using an IDE, I'd exit from the IDE, reboot the OS and try again. If it works first time after that, I would suspect that something in your code (or some other code) is tromping on memory. Unfortunately this type of 'bug' is very hard to find as it could have been caused by something else you ran an hour ago, and only surfaced an hour later. RE: A trouble with requests - snippsat - Feb-26-2019 Find a file you have called email.py and rename to eg my_email.py .Then try Requests again. RE: A trouble with requests - Truman - Feb-26-2019 Thank you snippsat, good eye, now everything works fine. |