【问题标题】:Unable to open Instagram mobile version using Selenium?无法使用 Selenium 打开 Instagram 移动版?
【发布时间】:2019-05-27 07:40:03
【问题描述】:

因此,我正在尝试创建一个自动机器人以在 Instagram 上发帖,但我无法使用 selenium 打开移动版 Instagram。

我尝试过使用

from selenium.webdriver.common.keys import Keys
chrome_options = Options()
chrome_options.add_argument("--window-size=200,700")

在 selenium 中设置我的 chrome 窗口的大小,但它仍然打开桌面版本。

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

def site_login():
    driver = webdriver.Chrome(executable_path='//home/kartikey/Desktop/Files/Insta_Bot/chromedriver',chrome_options=chrome_options)
    driver.get ('https://www.instagram.com/accounts/login/')
    time.sleep(3)
    # To login
    driver.find_element_by_name("username").send_keys('EMAIL')
    passwordInput = driver.find_element_by_name("password")
    passwordInput.send_keys('*******')
    passwordInput.send_keys(Keys.ENTER)
    # To turn on Notifications
    driver.find_element_by_xpath('/html/body/div[3]/div/div/div/div[3]/button[1]').click() 
    return None
site_login()

我可以访问桌面版,但桌面版不允许发布。

那么,我想知道如何使用 selenium 来打开移动版 Instagram?

【问题讨论】:

  • 你试过thisthis吗?
  • 其实用mobile_emulation = { "deviceName": "Nexus 5" } chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)chromedriver 找到了答案
  • 跟答案一样发帖

标签: python selenium web


【解决方案1】:

因此,我通过在Chrome Options 中使用Mobile Emulation 解决了上述问题,这有助于模拟Instagram 的移动版本并启用通过网络发布的功能。

mobile_emulation = { "deviceName": "Nexus 5" }
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

【讨论】:

  • 为什么不给浏览器设置一个移动用户代理?
  • chrome 已提供此功能。所以,我使用了它,并将研究user_agent
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
  • 1970-01-01
  • 2015-12-28
相关资源
最近更新 更多