首页 > 解决方案 > 如何使用指定的浏览器获取 url?

问题描述

这是我的代码:

import requests
from bs4 import BeautifulSoup

Url = "https://gmail.com"
R = requests.get(Url)
Soup = BeautifulSoup(R.text,"lxml")
print(Soup)

但我需要我的 cookie、登录数据和其他东西,它们存储在谷歌浏览器中,所以我想通过谷歌浏览器获取 url。

Google Chrome 的路径:“C:\Program Files\Google\Chrome\Application\chrome.exe”

那可能吗?谢谢...

标签: pythonhtmlbeautifulsouplxml

解决方案


问题是你必须使用 selenium,下载 chrome webdriver `options = webdriver.ChromeOptions() options.add_argument('--start-maximized') options.add_argument('--disable-extensions')

driver_path='C:\Users\your_user_here\Downloads\chromedriver.exe'

driver = webdriver.Chrome(driver_path, chrome_options=options)`


推荐阅读