简体   繁体   中英

Can't run python beautifulsoup web scraping program because of OSError

I am trying to web scrape an Instagram account and i am getting an error:

Traceback (most recent call last):
  File "C:/Users/User/Desktop/python/webscraper.py", line 11, in <module>
    browser = webdriver.Chrome(r"C:\Users\User\Downloads\chromedriver_win32.zip")
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

I am trying to run this code:

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:\Users\User\Downloads\chromedriver_win32.zip")
browser.get('https://www.instagram.com/'+username+'/?hl=en')
Pagelength = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")

I don't understand what i am doing wrong. I have tried looking up this error but none of the solutions on GitHub or other stack overflow question are solving the problem.

The Problem:

browser = webdriver.Chrome(r"C:\Users\User\Downloads\chromedriver_win32.zip")

You are pointing to a .zip file rather than an executable for the chrome driver. You need to unzip this file and then point to that executable.

Solution:

Once you have unzipped this file in the same location you can do:

browser = webdriver.Chrome(r"C:\Users\User\Downloads\chromedriver_win32.exe")

Notice the change from .zip to .exe meaning executable.

You are considering a zip file as your chromedriver.

Try to unzip it and point your webdriver.Chrome to the executable file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM