I had a problem running my code, and found a perfect solution for this on StackOverflow. But, when I make necessary changes and run it, I get no output.
Code:
from bs4 import BeautifulSoup
import urllib.parse
import requests
r = requests.get('https://duckduckgo.com/html/?q=test')
soup = BeautifulSoup(r.text, 'html.parser')
results = soup.find_all('a', attrs={'class':'result__url'}, href=True)
for link in results:
url = link['href']
o = urllib.parse.urlparse(url)
d = urllib.parse.parse_qs(o.query)
print(d['uddg'][0])
urlparse() for path components
" From this take the query string and pass it to parse_qs()
to further process it. You can then extract the link using the uddg
name."
This is supposed to be the first few results:
http://www.speedtest.net/
https://www.merriam-webster.com/dictionary/test
https://en.wikipedia.org/wiki/Test
https://www.thefreedictionary.com/test
https://www.dictionary.com/browse/test
I get no output. Output:
In [13]: runfile('C:/Users/Spurs/.spyder-py3/temp.py', wdir='C:/Users/Spurs/.spyder-py3')
In [14]: