我试图通过网络刮取一个Instagram帐户,但我收到了一个错误:
Traceback (most recent call last):
File "C:/Users/User/Desktop/python/webscraper.py", line 11, in <module>
browser = webdriver.Chrome(r"C:UsersUserDownloadschromedriver_win32.zip")
File "C:UsersUserAppDataLocalProgramsPythonPython38-32libsite-packagesseleniumwebdriverchromewebdriver.py", line 73, in __init__
self.service.start()
File "C:UsersUserAppDataLocalProgramsPythonPython38-32libsite-packagesseleniumwebdrivercommonservice.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:UsersUserAppDataLocalProgramsPythonPython38-32libsubprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:UsersUserAppDataLocalProgramsPythonPython38-32libsubprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
我正在尝试运行此代码:
from selenium import webdriver
from bs4 import BeautifulSoup as bs
import time
import re
from urllib.request import urlopen
import json
from pandas.io.json import json_normalize
import pandas as pd, numpy as np
username='dailydogsnapz'
browser = webdriver.Chrome(r"C:UsersUserDownloadschromedriver_win32.zip")
browser.get('https://www.instagram.com/'+username+'/?hl=en')
Pagelength = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
我不明白我做错了什么。我试着查找这个错误,但GitHub上的解决方案或其他堆栈溢出问题都无法解决这个问题。
问题:
browser = webdriver.Chrome(r"C:UsersUserDownloadschromedriver_win32.zip")
您指向的是.zip
文件,而不是chrome驱动程序的可执行文件。您需要解压缩这个文件,然后指向那个可执行文件。
解决方案:
一旦你在同一个位置解压缩了这个文件,你可以做:
browser = webdriver.Chrome(r"C:UsersUserDownloadschromedriver_win32.exe")
请注意从.zip
更改为.exe
,意思是可执行
您正在考虑将zip文件作为chromedriver。
尝试解压缩它并将webdriver.Chrome
指向可执行文件。