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)
错误代码:
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'
这部分保持返回错误,我不知道如何解决这个问题。我想这可能是因为Chrome和chromedriver
的版本不同,所以我试着下载了相同的版本。但是Chrome的版本是116.0.5845.97
,而且没有相同版本的chromedriver
可供我下载。如果你能告诉我一个修复这个错误的方法,那就太好了。请发送帮助
1条答案
按热度按时间6l7fqoea1#
对于selenium
v4.10.0
,您需要在Service
类中传递executable_path
。参考如下:话虽如此,如果你不想手动设置
chromedriver.exe
路径,那么你可以简化代码如下:Selenium的新工具
Selenium Manager
将为您下载和管理driver.exe
。参考文献: