繁体   English   中英

如何将 header “Access-Control-Allow-Origin”设置为 selenium Webdriver

[英]How to set header “Access-Control-Allow-Origin” to selenium Webdriver

我是 python selenium 的初学者。 我赞赏的任何帮助。

我的 selenium 代码:

user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) ' \
    'Chrome/80.0.3987.132 Safari/537.36'
chrome_option = webdriver.ChromeOptions()
chrome_option.add_argument('--no-sandbox')
chrome_option.add_argument('--disable-dev-shm-usage')
chrome_option.add_argument('--ignore-certificate-errors')
chrome_option.add_argument("--disable-blink-features=AutomationControlled")
chrome_option.add_argument(f'user-agent={user_agent}')
chrome_option.headless = True

driver = webdriver.Chrome(options = chrome_option)
driver.get("https://apps.apple.com/us/app/tiktok-make-your-day/id835599320#see-all/reviews")

我收到以下错误消息:

[0708/203913.943:INFO:CONSOLE(0)] "Access to font at 'https://www.apple.com/ac/globalfooter/3/en_US/assets/ac-footer/legacy/appleicons_text.woff' from origin 'https://apps.apple.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.", source: https://apps.apple.com/us/app/tiktok-make-your-day/id835599320#see-all/reviews (0)
[0708/203914.012:INFO:CONSOLE(8199)] "Metrics config: No config provided via delegate or fetched via init(), using default/cached config values.", source: https://apps.apple.com/assets/vendor-5715c00de8dadd4a8dd6d176ecd12d82.js (8199)
[0708/203914.022:INFO:CONSOLE(8199)] "Metrics config: No config provided via delegate or fetched via init(), using default/cached config values.", source: https://apps.apple.com/assets/vendor-5715c00de8dadd4a8dd6d176ecd12d82.js (8199)
[0708/203914.027:INFO:CONSOLE(6946)] "ember-i18n has been deprecated in favor of ember-intl", source: https://apps.apple.com/assets/vendor-5715c00de8dadd4a8dd6d176ecd12d82.js (6946)
[0708/203915.024:INFO:CONSOLE(0)] "Access to font at 'https://www.apple.com/ac/globalfooter/3/en_US/assets/ac-footer/legacy/appleicons_text.ttf' from origin 'https://apps.apple.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.", source: https://apps.apple.com/us/app/tiktok-make-your-day/id835599320#see-all/reviews (0)

我期待着听到你的声音。 问候!

从您的问题来看,为什么必须使用以下论点尚无定论:

  • --disable-blink-features=AutomationControlled

也许通过简单的调整,我可以成功访问 url,如下所示:

代码块:

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://apps.apple.com/us/app/tiktok-make-your-day/id835599320#see-all/reviews')
print(driver.page_source)

控制台 Output:

<html lang="en-us" prefix="og: http://ogp.me/ns#" xml:lang="en-us"><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    .
    .
  <meta name="description" content="‎Read reviews, compare customer ratings, see screenshots, and learn more about TikTok - Make Your Day. Download TikTok - Make Your Day and enjoy it on your iPhone, iPad, and iPod touch." id="ember15042807" class="ember-view">

  <meta name="keywords" content="TikTok - Make Your Day, TikTok Inc., Entertainment, Photo &amp; Video, ios apps, app, appstore, app store, iphone, ipad, ipod touch, itouch, itunes" id="ember15042809" class="ember-view">

  <meta property="og:title" content="‎TikTok - Make Your Day" id="ember15042811" class="ember-view">

  <meta property="og:description" content="‎TikTok is THE destination for mobile videos. On TikTok, short-form videos are exciting, spontaneous, and genuine. Whether you’re a sports fanatic, a pet enthusiast, or just looking for a laugh, there’s something for everyone on TikTok. All you have to do is watch, engage with what you like, skip wha…" id="ember15042813" class="ember-view">

  <meta property="og:site_name" content="App Store" id="ember15042815" class="ember-view">

  <meta property="og:url" content="https://apps.apple.com/us/app/tiktok-make-your-day/id835599320" id="ember15042817" class="ember-view">

  <meta property="og:image" content="https://is2-ssl.mzstatic.com/image/thumb/Purple124/v4/b7/54/52/b7545217-dbd1-c219-ce00-00189f3b739e/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/1200x630wa.png" id="ember15042819" class="ember-view">

  <meta property="og:image:alt" content="TikTok - Make Your Day on the App&nbsp;Store" id="ember15042821" class="ember-view">

  <meta property="og:image:secure_url" content="https://is2-ssl.mzstatic.com/image/thumb/Purple124/v4/b7/54/52/b7545217-dbd1-c219-ce00-00189f3b739e/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/1200x630wa.png" id="ember15042823" class="ember-view">

  <meta property="og:image:type" content="image/png" id="ember15042825" class="ember-view">

  <meta property="og:image:width" content="1200" id="ember15042827" class="ember-view">

  <meta property="og:image:height" content="630" id="ember15042829" class="ember-view">

  <meta property="og:type" content="website" id="ember15042831" class="ember-view">

  <meta property="og:locale" content="en_US" id="ember15042833" class="ember-view">

  <meta property="fb:app_id" content="116556461780510" id="ember15042835" class="ember-view">

  <meta name="twitter:title" content="‎TikTok - Make Your Day" id="ember15042837" class="ember-view">

  <meta name="twitter:description" content="‎TikTok is THE destination for mobile videos. On TikTok, short-form videos are exciting, spontaneous, and genuine. Whether you’re a sports fanatic, a pet enthusiast, or just looking for a laugh, there’s something for everyone on TikTok. All you have to do is watch, engage with what you like, skip wha…" id="ember15042839" class="ember-view">

  <meta name="twitter:site" content="@AppStore" id="ember15042841" class="ember-view">

  <meta name="twitter:domain" content="AppStore" id="ember15042843" class="ember-view">

  <meta name="twitter:image" content="https://is2-ssl.mzstatic.com/image/thumb/Purple124/v4/b7/54/52/b7545217-dbd1-c219-ce00-00189f3b739e/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/600x600wa.png" id="ember15042845" class="ember-view">

  <meta name="twitter:image:alt" content="TikTok - Make Your Day on the App&nbsp;Store" id="ember15042847" class="ember-view">

  <meta name="twitter:card" content="summary_large_image" id="ember15042849" class="ember-view">

  <meta name="apple-itunes-app" content="app-id=375380948, app-argument=https://apps.apple.com/us/app/tiktok-make-your-day/id835599320" id="ember15042851" class="ember-view">

  <script name="schema:software-application" id="ember15042853" class="ember-view" type="application/ld+json">{"@context":"http://schema.org","@type":"SoftwareApplication","name":"TikTok - Make Your Day","description":"TikTok is THE destination for mobile videos. On TikTok, short-form videos are exciting, spontaneous, and genuine. Whether you’re a sports fanatic, a pet enthusiast, or just looking for a laugh, there’s something for everyone on TikTok. All you have to do is watch, engage with what you like, skip what you don’t, and you’ll find an endless stream of short videos that feel personalized just for you. From your morning coffee to your afternoon errands, TikTok has the videos that are guaranteed to make your day.\n\nWe make it easy for you to discover and create your own original videos by providing easy-to-use tools to view and capture your daily moments. Take your videos to the next level with special effects, filters, music, and more. \n\n■ Watch endless amount of videos customized specifically for you\nA personalized video feed based on what you watch, like, and share. TikTok offers you real, interesting, and fun videos that will make your day.\n \n■ Explore videos, just one scroll away\nWatch all types of videos, from Comedy, Gaming, DIY, Food, Sports, Memes, and Pets, to Oddly Satisfying, ASMR, and everything in between.\n \n■ Pause recording multiple times in one video\nPause and resume your video with just a tap. Shoot as many times as you need.\n \n■ Be entertained and inspired by a global community of creators\nMillions of creators are on TikTok showcasing their incredible skills and everyday life. Let yourself be inspired.\n\n■ Add your favorite music or sound to your videos for free\nEasily edit your videos with millions of free music clips and sounds. We curate music and sound playlists for you with the hottest tracks in every genre, including Hip Hop, Edm, Pop, Rock, Rap, and Country, and the most viral original sounds.\n\n■ Express yourself with creative effects\nUnlock tons of filters, effects, and AR objects to take your videos to the next level.\n\n■ Edit your own videos \nOur integrated editing tools allow you to easily trim, cut, merge and duplicate video clips without leaving the app.\n\n* Any feedback? Contact us at feedback@tiktok.com or tweet us @tiktok_us","screenshot":["https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/ab/10/3d/ab103d22-efca-509b-312a-f2ff2feb819d/pr_source.png/300x0w.jpg","https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/d3/30/6b/d3306b31-f0e1-fed0-683c-44899a9c0b5d/pr_source.png/300x0w.jpg","https://is2-ssl.mzstatic.com/image/thumb/Purple123/v4/03/88/18/038818fa-44c6-9289-f9b7-fc1d67273fde/pr_source.png/300x0w.jpg","https://is5-ssl.mzstatic.com/image/thumb/Purple123/v4/67/ee/ad/67eead34-780b-5aae-4be7-574ccdd4010a/pr_source.png/300x0w.jpg","https://is5-ssl.mzstatic.com/image/thumb/Purple123/v4/71/6f/da/716fdafc-b9ef-856f-5ce1-5ecf5b05a815/pr_source.png/300x0w.jpg","https://is4-ssl.mzstatic.com/image/thumb/Purple113/v4/98/7a/12/987a1281-b961-75a0-8da7-1e123bbada56/pr_source.jpg/643x0w.jpg","https://is4-ssl.mzstatic.com/image/thumb/Purple113/v4/27/3f/cd/273fcda9-05c6-3d16-1e7d-465cf7d5aa25/pr_source.jpg/643x0w.jpg","https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/c3/e6/7b/c3e67b5b-9159-50e9-9b62-558aa32cd605/pr_source.jpg/643x0w.jpg","https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/6c/ff/97/6cff975c-dcb6-253c-a63b-f30c7d465efc/pr_source.jpg/643x0w.jpg","https://is2-ssl.mzstatic.com/image/thumb/Purple123/v4/12/3a/bf/123abfb8-fda2-85bb-6419-a58eefd2af7f/pr_source.jpg/643x0w.jpg"],"image":"https://is2-ssl.mzstatic.com/image/thumb/Purple124/v4/b7/54/52/b7545217-dbd1-c219-ce00-00189f3b739e/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/1200x630wa.png","applicationCategory":"Entertainment","datePublished":"2014年4月1日","operatingSystem":"Requires iOS 9.3 or later. Compatible with iPhone, iPad, and iPod touch.","author":{"@type":"Person","name":"TikTok Inc.","url":"https://apps.apple.com/us/developer/tiktok-inc/id1039610913"},"aggregateRating":{"@type":"AggregateRating","ratingValue":4.7,"reviewCount":5397820},"offers":{"@type":"Offer","price":0,"priceCurrency":"USD","category":"free"}}
</script>
  <meta name="apple:content_id" content="835599320" id="ember15042855" class="ember-view">


<meta name="ember-cli-head-end" content="">
<link rel="stylesheet" type="text/css" href="/global-elements/2014.4.0/en_US/ac-global-nav.d915b46b2869cd416cbafe206ca74838.css" data-global-elements-nav-styles="">
<link rel="stylesheet" type="text/css" href="/global-elements/2014.4.0/en_US/ac-global-footer.23e044b4f5b5dd393dc9767d96faf248.css" data-global-elements-footer-styles="">

    <meta name="version" content="2026.2.0">

    <link integrity="" rel="stylesheet" href="/assets/web-experience-app-f1c50a018dab4bdb8c454bab56ac60a1.css" data-rtl="/assets/web-experience-rtl-app-bd50312cdbe2a58d742a5dbf295ff43a.css">


  <script charset="utf-8" src="https://apps.apple.com/assets/chunk.d1a0e2a45b401b141683.js"></script></head>
  <body class="ember-application has-js no-touch">
    <div id="ember-app">
      <script type="x/boundary" id="fastboot-body-start"></script><aside id="ac-gn-segmentbar" class="ac-gn-segmentbar" lang="en-US" dir="ltr" data-strings="{ 'exit': 'Exit', 'view': '{%STOREFRONT%} Store Home', 'segments': { 'smb': 'Business Store Home', 'eduInd': 'Education Store Home', 'other': 'Store Home' } }">
</aside>
<input type="checkbox" id="ac-gn-menustate" class="ac-gn-menustate">
<nav id="ac-globalnav" class="js no-touch windows" role="navigation" aria-label="Global" data-hires="false" data-analytics-region="global nav" lang="en-US" dir="ltr" data-www-domain="www.apple.com" data-store-locale="us" data-store-root-path="/us" data-store-api="https://www.apple.com/[storefront]/shop/bag/status" data-search-locale="en_US" data-search-suggestions-api="https://www.apple.com/search-services/suggestions/" data-search-defaultlinks-api="https://www.apple.com/search-services/suggestions/defaultlinks/">
    <div class="ac-gn-content">
        <ul class="ac-gn-header">
            <li class="ac-gn-item ac-gn-menuicon">
                <label class="ac-gn-menuicon-label" for="ac-gn-menustate" aria-hidden="true">
                    <span class="ac-gn-menuicon-bread ac-gn-menuicon-bread-top">
                        <span class="ac-gn-menuicon-bread-crust ac-gn-menuicon-bread-crust-top"></span>
                    </span>
                    <span class="ac-gn-menuicon-bread ac-gn-menuicon-bread-bottom">
                        <span class="ac-gn-menuicon-bread-crust ac-gn-menuicon-bread-crust-bottom"></span>
                    </span>
                </label>
                <a href="#ac-gn-menustate" role="button" class="ac-gn-menuanchor ac-gn-menuanchor-open" id="ac-gn-menuanchor-open">
                    <span class="ac-gn-menuanchor-label">Global Nav Open Menu</span>
                </a>
                <a href="#" role="button" class="ac-gn-menuanchor ac-gn-menuanchor-close" id="ac-gn-menuanchor-close">
                    <span class="ac-gn-menuanchor-label">Global Nav Close Menu</span>
                </a>
            </li>
            <li class="ac-gn-item ac-gn-apple">
                <a class="ac-gn-link ac-gn-link-apple" href="https://www.apple.com/" data-analytics-title="apple home" id="ac-gn-firstfocus-small">
                    <span class="ac-gn-link-text">Apple</span>
                </a>
            </li>
            <li class="ac-gn-item ac-gn-bag ac-gn-bag-small" id="ac-gn-bag-small">
                <div class="ac-gn-bag-wrapper">
                    <a class="ac-gn-link ac-gn-link-bag" href="https://www.apple.com/us/shop/goto/bag" data-analytics-title="bag" data-analytics-click="bag" aria-label="Shopping Bag" data-string-badge="Shopping Bag with item count :">
                        <span class="ac-gn-link-text">Shopping Bag</span>
                    </a>
                    <span class="ac-gn-bag-badge">
                        <span class="ac-gn-bag-badge-separator"></span>
                    <span class="ac-gn-bag-badge-number"></span>
                    <span class="ac-gn-bag-badge-unit">+</span>
                    </span>
                </div>
                <span class="ac-gn-bagview-caret ac-gn-bagview-caret-large"></span>
            </li>
        </ul>
        <div class="ac-gn-search-placeholder-container" role="search">
            <div class="ac-gn-search ac-gn-search-small">
                <a id="ac-gn-link-search-small" class="ac-gn-link" href="https://www.apple.com/us/search" data-analytics-title="search" data-analytics-click="search" data-analytics-intrapage-link="" aria-label="Search apple.com" role="button" aria-haspopup="true">
                    <div class="ac-gn-search-placeholder-bar">
                        <div class="ac-gn-search-placeholder-input">
                            <div class="ac-gn-search-placeholder-input-text" aria-hidden="true">
                                <div class="ac-gn-link-search ac-gn-search-placeholder-input-icon"></div>
                                <span class="ac-gn-search-placeholder">Search apple.com</span>
                            </div>
                        </div>
                        <div class="ac-gn-searchview-close ac-gn-searchview-close-small ac-gn-search-placeholder-searchview-close">
                            <span class="ac-gn-searchview-close-cancel" aria-hidden="true">Cancel</span>
                        </div>
                    </div>
                </a>
            </div>
        </div>
        <ul class="ac-gn-list">
            <li class="ac-gn-item ac-gn-apple">
                <a class="ac-gn-link ac-gn-link-apple" href="https://www.apple.com/" data-analytics-title="apple home" id="ac-gn-firstfocus">
                        <span class="ac-gn-link-text">Apple</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-mac">
                <a class="ac-gn-link ac-gn-link-mac" href="https://www.apple.com/mac/" data-analytics-title="mac">
                        <span class="ac-gn-link-text">Mac</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-ipad">
                <a class="ac-gn-link ac-gn-link-ipad" href="https://www.apple.com/ipad/" data-analytics-title="ipad">
                        <span class="ac-gn-link-text">iPad</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-iphone">
                <a class="ac-gn-link ac-gn-link-iphone" href="https://www.apple.com/iphone/" data-analytics-title="iphone">
                        <span class="ac-gn-link-text">iPhone</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-watch">
                <a class="ac-gn-link ac-gn-link-watch" href="https://www.apple.com/watch/" data-analytics-title="watch">
                        <span class="ac-gn-link-text">Watch</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-tv">
                <a class="ac-gn-link ac-gn-link-tv" href="https://www.apple.com/tv/" data-analytics-title="tv">
                        <span class="ac-gn-link-text">TV</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-music">
                <a class="ac-gn-link ac-gn-link-music" href="https://www.apple.com/music/" data-analytics-title="music">
                        <span class="ac-gn-link-text">Music</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-support">
                <a class="ac-gn-link ac-gn-link-support" href="https://support.apple.com" data-analytics-title="support">
                        <span class="ac-gn-link-text">Support</span>
                    </a>
            </li>
            <li class="ac-gn-item ac-gn-item-menu ac-gn-search" role="search">
                <a id="ac-gn-link-search" class="ac-gn-link ac-gn-link-search" href="https://www.apple.com/us/search" data-analytics-title="search" data-analytics-click="search" data-analytics-intrapage-link="" aria-label="Search apple.com" role="button" aria-haspopup="true"></a>
            </li>
            <li class="ac-gn-item ac-gn-bag" id="ac-gn-bag">
                <div class="ac-gn-bag-wrapper">
                    <a class="ac-gn-link ac-gn-link-bag" href="https://www.apple.com/us/shop/goto/bag" data-analytics-title="bag" data-analytics-click="bag" aria-label="Shopping Bag" data-string-badge="Shopping Bag with item count : {%BAGITEMCOUNT%}">
                            <span class="ac-gn-link-text">Shopping Bag</span>
                        </a>
                    <span class="ac-gn-bag-badge" aria-hidden="true">
                                <span class="ac-gn-bag-badge-separator"></span>
                    <span class="ac-gn-bag-badge-number"></span>
                    <span class="ac-gn-bag-badge-unit">+</span>
                    </span>
                </div>
                <span class="ac-gn-bagview-caret ac-gn-bagview-caret-large"></span>
            </li>
        </ul>
.
.
.
</div><footer id="ac-globalfooter" class="js flexbox" role="contentinfo" lang="en-US" dir="ltr"><div class="ac-gf-content"><section class="ac-gf-footer">
    <div class="ac-gf-footer-shop" x-ms-format-detection="none">
        More ways to shop: <a href="https://www.apple.com/retail/" data-analytics-title="find an apple store">Find an Apple Store</a> or <a href="https://locate.apple.com/" data-analytics-title="other retailers or resellers" data-analytics-exit-link="">other retailer</a> near you. <span class="nowrap">Or call 1-800-MY-APPLE.</span>
    </div>
    <div class="ac-gf-footer-locale">
        <a class="ac-gf-footer-locale-link" href="https://www.apple.com/choose-country-region/" title="Choose your country or region" aria-label="Choose your country or region" data-analytics-title="choose your country"><span class="ac-gf-footer-locale-flag" data-hires="false"></span>Choose your country or region</a>
    </div>
    <div class="ac-gf-footer-legal">
        <div class="ac-gf-footer-legal-copyright">Copyright © 2020 Apple Inc. All rights reserved.</div>
        <div class="ac-gf-footer-legal-links">
            <a class="ac-gf-footer-legal-link" href="https://www.apple.com/legal/privacy/" data-analytics-title="privacy policy">Privacy Policy</a>
            <a class="ac-gf-footer-legal-link" href="https://www.apple.com/legal/internet-services/terms/site.html" data-analytics-title="terms of use">Terms of Use</a>
            <a class="ac-gf-footer-legal-link" href="https://www.apple.com/us/shop/goto/help/sales_refunds" data-analytics-title="sales and refunds">Sales and Refunds</a>
            <a class="ac-gf-footer-legal-link" href="https://www.apple.com/legal/" data-analytics-title="legal">Legal</a>
            <a class="ac-gf-footer-legal-link" href="https://www.apple.com/sitemap/" data-analytics-title="site map">Site Map</a>
        </div>
    </div>
</section>
</div></footer>
.
.
.
    </div>
    <div id="modal-container"></div>
    <script integrity="" src="/assets/vendor-5715c00de8dadd4a8dd6d176ecd12d82.js"></script><div id="ac-gn-viewport-emitter"> </div>
    <script integrity="" src="/assets/web-experience-app-26d37fb2d982f3cfebb0a2498926aa6e.js"></script>
    <script src="https://js-cdn.music.apple.com/-amp/v2/musickit.js"></script>

    <div id="ember-basic-dropdown-wormhole"></div>


</body></html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM