简体   繁体   English

Selenium 无效参数异常 - python

[英]Selenium invalid argument exception - python

As a practice I am trying to create a simple took to scrape a website in python.作为一种实践,我正在尝试创建一个简单的方法来抓取 python 中的网站。 Below is the code:下面是代码:

from bs4 import BeautifulSoup
import pandas as pd
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

products=[] #List to store name of the product
prices=[] #List to store price of the product
ratings=[] #List to store rating of the product
driver.get("<a href='https://www.flipkart.com/laptops/~buyback-guarantee-on-laptops-/pr?sid=6bo%2Cb5g&uniqBStoreParam1=val1&wid=11.productCard.PMU_V2'></a>")

content = driver.page_source
soup = BeautifulSoup(content)
for a in soup.findAll('a',href=True, attrs={'class':'_31qSD5'}):
    name=a.find('div', attrs={'class':'_3wU53n'})
    price=a.find('div', attrs={'class':'_1vC4OE _2rQ-NK'})
    rating=a.find('div', attrs={'class':'hGSR34 _2beYZw'})
products.append(name.text)
prices.append(price.text)
ratings.append(rating.text) 

df = pd.DataFrame({'Product Name':products,'Price':prices,'Rating':ratings}) 
df.to_csv('products.csv', index=False, encoding='utf-8')

The issue I am having is that it is throwing an exception in my webdriver manager and I am not sure how to figure it out.我遇到的问题是它在我的 webdriver 管理器中引发异常,我不知道如何解决。

====== WebDriver manager ======
Current google-chrome version is 90.0.4430
Get LATEST driver version for 90.0.4430
Driver [/Users/mpl07/.wdm/drivers/chromedriver/mac64/90.0.4430.24/chromedriver] found in cache
Traceback (most recent call last):
  File "/Users/mpl07/Documents/scraper.py", line 12, in <module>
    driver.get("<a href='https://www.flipkart.com/laptops/~buyback-guarantee-on-laptops-/pr?sid=6bo%2Cb5g&uniqBStoreParam1=val1&wid=11.productCard.PMU_V2'></a>")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
  (Session info: chrome=90.0.4430.212)

Fixed it.解决它。 Do not include HTML link tags in the driver.get() method.不要在driver.get()方法中包含 HTML 链接标签。

So it should be:所以应该是:

driver.get("https://www.flipkart.com/laptops/~buyback-guarantee-on-laptops-/pr?sid=6bo%2Cb5g&uniqBStoreParam1=val1&wid=11.productCard.PMU_V2")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python selenium 参数无效? - Python selenium invalid argument? 如何解决 Selenium 异常:“invalid argument 'url' must be a string” - How to solve Selenium exception: “ invalid argument 'url' must be a string ” Selenium 获取元素时抛出无效参数异常 - Selenium throws invalid argument exception when getting an element Selenium 和 Python 错误:消息:无效参数:“使用”必须是字符串 - Selenium and Python Error: Message: invalid argument: 'using' must be a string 无效的参数引发异常 - Invalid argument raise exception Python selenium 用于撰写评论谷歌地图(selenium.common.exceptions.InvalidArgumentException:消息:无效参数:无效定位器) - Python selenium for write review google maps (selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator ) Python bool()函数可以为无效参数引发异常吗? - Can the Python bool() function raise an exception for an invalid argument? selenium.common.exceptions.InvalidArgumentException:消息:使用 Selenium Webdriver 通过 Python 调用 get() 时参数无效错误 - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() using Selenium Webdriver through Python Selenium:消息:无效参数:无效的“sameSite” - Selenium: Message: invalid argument: invalid 'sameSite' 已解决:python:selenium.common.exceptions.InvalidArgumentException:消息:无效参数:无效定位器 - solved: python: selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM