当我使用Selenium启动的浏览器时,TickTok网站不允许查看用户个人资料。我什至尝试只是启动浏览器并手动执行所有操作,但这没有帮助。
这是我用来解决问题的方法,但这没有帮助:
我注意到,没有Selenium,在普通的浏览器中,对我来说没有任何障碍。我使用Chrome和Python。
我的代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
opts = Options()
ua = UserAgent()
userAgent = ua.random
opts.add_argument(f'user-agent={userAgent}')
opts.add_argument("window-size=1920,1080")
d = webdriver.Chrome(chrome_options=opts, executable_path=r'driver/chromedriver2.exe')
link = 'https://www.tiktok.com/'
d.get(link)
inpute('Pause . . .')
d.quit()
答案 0 :(得分:0)
我接受了您的代码并进行了一些调整,然后执行了测试,以下是观察结果:
注意:此观察结果特定于印度的互联网用户。
代码块:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.tiktok.com/')
print(driver.page_source)
控制台输出:
<html><head>
<script>
window._I18N_LANG_ = 'en';
.
</style>
</head>
<body style="margin-top: 0px;">
<div class="root">
<header style="top: 0px;">
.
</header>
<section>
<article>
<p>Dear Users,</p>
<p>
On June 29, 2020 the Govt. of India decided to block 59 apps, including TikTok. We are in the process of
complying with the Government of India's directive and also working with
the government to better understand the issue and explore a course of action.
</p>
<p>
Ensuring the privacy and security of all our users in India remains our utmost priority.
</p>
<p>
TikTok India Team.
</p>
<p>
Follow us on <a href="https://twitter.com/tiktok_in">Twitter</a> and <a href="https://instagram.com/indiatiktok?igshid=40wmgad5gauz">Instagram</a>.
</p>
</article>
</section>
</div>
</body></html>
这一观察结果与政府完全吻合。印度决定取消阻止59个应用程序,包括TikTok,这些应用程序可以手动访问TicTok Home Page登录页面进行复制。
浏览器快照: