Hobr / bilibili_show_selenium_deprecate

https://github.com/Just-Prog/Bilibili_show_ticket_auto_order
71 stars 23 forks source link

运行cpp.py报错 #15

Closed sifeizhai2017 closed 1 year ago

sifeizhai2017 commented 1 year ago

预期行为

正常打开页面并开始购票

当前行为

运行后出现如下报错

Traceback (most recent call last):
  File "/Users/hitori/Developer/comicup29-ticket-buy/cpp.py", line 34, in <module>
    WebDriver.add_cookie(
  File "/Users/hitori/opt/anaconda3/envs/comicup29-ticket-buy/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 727, in add_cookie
    self.execute(Command.ADD_COOKIE, {"cookie": cookie_dict})
  File "/Users/hitori/opt/anaconda3/envs/comicup29-ticket-buy/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/Users/hitori/opt/anaconda3/envs/comicup29-ticket-buy/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidCookieDomainException: Message: invalid cookie domain: Cookie 'domain' mismatch
  (Session info: MicrosoftEdge=112.0.1722.58)
Stacktrace:
0   msedgedriver                        0x000000010d7ec9a8 msedgedriver + 5167528
1   msedgedriver                        0x000000010d7e40b3 msedgedriver + 5132467
2   msedgedriver                        0x000000010d375c26 msedgedriver + 486438
3   msedgedriver                        0x000000010d414ac4 msedgedriver + 1137348
4   msedgedriver                        0x000000010d3e4732 msedgedriver + 939826
5   msedgedriver                        0x000000010d40097d msedgedriver + 1055101
6   msedgedriver                        0x000000010d3e4503 msedgedriver + 939267
7   msedgedriver                        0x000000010d3adb37 msedgedriver + 715575
8   msedgedriver                        0x000000010d3af72e msedgedriver + 722734
9   msedgedriver                        0x000000010d7a656d msedgedriver + 4879725
10  msedgedriver                        0x000000010d7ab2c3 msedgedriver + 4899523
11  msedgedriver                        0x000000010d7abaea msedgedriver + 4901610
12  msedgedriver                        0x000000010d7b284f msedgedriver + 4929615
13  msedgedriver                        0x000000010d7ac28c msedgedriver + 4903564
14  msedgedriver                        0x000000010d7802e1 msedgedriver + 4723425
15  msedgedriver                        0x000000010d7ce618 msedgedriver + 5043736
16  msedgedriver                        0x000000010d7ce7c3 msedgedriver + 5044163
17  msedgedriver                        0x000000010d7de4d8 msedgedriver + 5108952
18  libsystem_pthread.dylib             0x00007ff8062c61d3 _pthread_start + 125
19  libsystem_pthread.dylib             0x00007ff8062c1bd3 thread_start + 15

重现步骤

  1. 配置Edge的WebDriver,安装到~/opt/anaconda3/bin目录下
  2. 创建并激活新的虚拟环境comicup29-ticket-buy
  3. 安装依赖:pip install -r requirements.txt
  4. 修改Web驱动程序,将所有出现Chrome()的部分改为Edge()
  5. 运行cpp.py
  6. 输入yes,并在打开的窗口登陆账号并自动保存cookie
  7. 再次执行cpp.py,出现如上报错

详细说明

  1. 只有cpp的不能运行,b站的在自动配置cookie之后是能够正常运行的
  2. Cookie确实是写进config.json去的

其他信息

  1. 系统版本:macOS 13.3.1 22E261 x86_64
  2. python版本:3.11.3
  3. Edge版本:版本 112.0.1722.58 (正式版本) (x86_64)
Kouria commented 1 year ago

from selenium import webdriver from selenium.common import TimeoutException from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Edge()

driver.get("https://cp.allcpp.cn/#/login/main?return_url=https%3A%2F%2Fcp.allcpp.cn%2F%23%2Fticket%2Fdetail%3Fevent%3D1074")

try: element = WebDriverWait(driver, 60).until( EC.presence_of_element_located((By.ID, "login_button")) ) except TimeoutException: print("Element not found within 60 seconds")

cookies = driver.get_cookies()

print(cookies)

执行该代码 登录后看是否报错 若报错请附报错数据

Hobr commented 1 year ago

cookie里有一个域名是异端,删掉他

sifeizhai2017 commented 1 year ago

cookie里有一个域名是异端,删掉他

我看到2个".allcpp.cn"的,2个".store.allcpp.cn",我应该怎么删?

sifeizhai2017 commented 1 year ago

登陆好之后没报错,然后cookie也正常打印出来的

sifeizhai2017 commented 1 year ago

@Hobr @Kouria config.json里面把cpp的cookie删了重新生成一下就好了,现在能跑起来了

Hobr commented 1 year ago

@Hobr @Kouria config.json里面把cpp的cookie删了重新生成一下就好了,现在能跑起来了

我也遇到过一次这个问题,当时删了一段什么来着忘了,看来这个问题还得解决一下......

Hobr commented 1 year ago

已放弃allcpp支持