【问题标题】:How to get url with specifed browser?如何使用特定浏览器获取 url?
【发布时间】:2021-09-13 11:55:33
【问题描述】:

这是我的代码:

import requests
from bs4 import BeautifulSoup

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

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

谷歌浏览器的路径:“C:\Program Files\Google\Chrome\Application\chrome.exe”

这可能吗?谢谢...

【问题讨论】:

  • 如果你想使用浏览器打开一个网址...使用浏览器。如果你想用给定的 url 打开一个浏览器,把它叫做“path_to_chrome_exe url”......但是如果你想使用带有 chrome cookie 的请求,看看here
  • @Sr.S 嗯那么我怎么能在这段代码上做到这一点?其实我还有别的想法。
  • 请看一下我发布的网址。有一些例子。
  • @Sr.S 谢谢,但他们不适合这个项目

标签: python html beautifulsoup lxml


【解决方案1】:

问题是你必须使用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)`

【讨论】:

  • 感谢工作,但有没有其他方法可以使用我自己的 chrome.exe 进行网络抓取?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
  • 2014-12-18
  • 2013-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多