Oct-10-2018, 11:54 PM
The last time I was doing an automatization of search ( on google ) it was with bs4 and webbrowser only. Now I'm trying to use selenium first. So, I want to achieve this:
1. open a browser
2. open yahoo search page
3. search for term 'seleniumhq'
4. open first 5 results in 5 different tabs
in later stage when I improve the algorithm planning to bundle it into functions and with input() but first want my basic code to work. Help is appreciated.
code:
1. open a browser
2. open yahoo search page
3. search for term 'seleniumhq'
4. open first 5 results in 5 different tabs
in later stage when I improve the algorithm planning to bundle it into functions and with input() but first want my basic code to work. Help is appreciated.
code:
from selenium import webdriver from selenium.webdriver.common.keys import Keys import bs4 browser = webdriver.Firefox() browser.get('http://www.yahoo.com') assert 'Yahoo' in browser.title elem = browser.find_element_by_name('p') # find the search box res = elem.send_keys('seleniumhq' + Keys.RETURN) soup = bs4.BeautifulSoup(res.text, "html.parser") linkElems = soup.select('a') for link in linkElems: print(f'link: {link}') numOpen = min(5, len(linkElems)) for i in range(numOpen): webbrowser.open(linkElems[i].get('href')) browser.quiterror:
Error:Traceback (most recent call last):
File "C:\Python36\kodovi\sel4.py", line 12, in <module>
soup = bs4.BeautifulSoup(res.text, "html.parser")
AttributeError: 'NoneType' object has no attribute 'text'
According to this res is nontype object. Don't know why and don't know how to make it type so that code can be fully conducted ( although not sure that the rest is good ).