def insta_searching(word):
url = "https://www.instagram.com/explore/tags/" + str(word)
return url
def select_first(driver):
first = driver.find_element_by_css_selector("div._9AhH0")[0] # Updated selector for the first post
first.click()
time.sleep(3)
def get_content(driver):
html = driver.page_source
soup = BeautifulSoup(html, 'lxml')
try:
content = soup.select('div.C4VMK > span')[0].text # Updated selector for post content
except:
content = ''
tags = re.findall(r'#[^\s#,\\]+', content)
date = soup.select('time.FH9sR.Nzb55')[0]['datetime'][:10] # Updated selector for post date
try:
place = soup.select('div.M30cS')[0].text # Updated selector for post location
except:
place = ''
data = [content, date, place, tags]
return data
def move_next(driver):
right = driver.find_element_by_css_selector("a._65Bje.coreSpriteRightPaginationArrow") # Updated selector for right arrow
right.click()
time.sleep(3)
driver = webdriver.Chrome(executable_path=r'C:\Users\Smart\Desktop\chromedriver-win64\chromedriver.exe')
driver.get('https://www.instagram.com') # Fixed line
time.sleep(3)
Error:
TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_11388\2581174010.py in <module>
----> 1 driver = webdriver.Chrome(executable_path=r'C:\Users\Smart\Desktop\chromedriver-win64\chromedriver.exe')
2
3 driver.get('https://www.instagram.com') # Fixed line
4 time.sleep(3)
TypeError: __init__() got an unexpected keyword argument 'executable_path'
This part keeps returns error and I don't know how to fix this.
I thought this might be because the version of chrome and chromedriver
is different so I tried to download the same version. But the version for chrome is 116.0.5845.97
and there aren't the same version of chromedriver
available for me to download. It would be wonderful if you can tell me a way to fix this error. please send help
With selenium v4.10.0
, you need to pass executable_path
in Service
class. Refer below:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path='./chromedriver.exe')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
Having said that, if you do not want to set the chromedriver.exe
path manually, then you can simplify the code as below:
driver = webdriver.Chrome()
driver.get('https://www.instagram.com')
Selenium's new tool Selenium Manager
will do the download and management of driver.exe
for you.
References: