前提・実現したいこと
Djangoでseleniumを使うと下記のようなエラーがでてしまいます。ブラウザで使っているgooglechromeのバージョンとchromedriver_binaryのバージョンはしっかり合わせれているようです。なぜこのようなエラーが出てしまうのでしょうか??ぜひ教えていただきたいです。
よろしくお願いします。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "/Users/.local/share/virtualenvs/wo-kkDshSZx/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/Users/.local/share/virtualenvs/wo-kkDshSZx/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/newswo/ws/views.py", line 33, in listfunc ul_tag = driver.find_elements_by_css_selector(selector) File "/Users/local/share/virtualenvs/wo-kkDshSZx/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 614, in find_elements_by_css_selector return self.find_elements(by=By.CSS_SELECTOR, value=css_selector) File "/Users/.local/share/virtualenvs/wo-kkDshSZx/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 1005, in find_elements return self.execute(Command.FIND_ELEMENTS, { File "/Users/.local/share/virtualenvs/wo-kkDshSZx/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/Users/.local/share/virtualenvs/wo-kkDshSZx/lib/python3.8/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: 'value' must be a string (Session info: headless chrome=84.0.4147.135)
該当のソースコード
from django.shortcuts import render from django.views.generic import CreateView from django.urls import reverse_lazy import urllib.request from .models import Post from .models import News from selenium import webdriver import chromedriver_binary from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options import requests options = Options() options.headless = True options.add_argument('--headless') class Create(CreateView): template_name = 'home.html' model = News fields = ('url',) success_url = reverse_lazy('list') def listfunc(request): for post in News.objects.all(): url = post.url list = [] driver = webdriver.Chrome(options=options) selector = driver.get("動的なwebサイト") ul_tag = driver.find_elements_by_css_selector(selector) for tag in ul_tag[0]: title = tag.a.getText() url2 = tag.a.get("href") list.append([title, url2]) context = {'list': list, } return render(request, 'list.html', context)
補足情報(FW/ツールのバージョンなど)
mac10.15.3
Python3.8.5
Django3.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/31 03:01