浏览代码

打印用户代理信息

xyxie 1 年之前
父节点
当前提交
adc2c2b98b
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      metting.py

+ 3 - 1
metting.py

@@ -86,7 +86,7 @@ if __name__ == "__main__":
     options.add_argument('--headless')
     options.add_argument('--headless')
     options.add_argument('--disable-gpu')
     options.add_argument('--disable-gpu')
     options.add_argument('--no-sandbox')
     options.add_argument('--no-sandbox')
-    options.add_argument('--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Safari/537.36')
+    # options.add_argument('--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Safari/537.36')
     options.add_argument(" window-size=1920,1080")
     options.add_argument(" window-size=1920,1080")
     # options.add_argument(" window-size=1920,1080")
     # options.add_argument(" window-size=1920,1080")
     s = Service(executable_path='/home/code/python/meeting_probabilities/chromedriver')
     s = Service(executable_path='/home/code/python/meeting_probabilities/chromedriver')
@@ -103,6 +103,8 @@ if __name__ == "__main__":
     driver.get(
     driver.get(
         'https://www.cmegroup.com/markets/interest-rates/cme-fedwatch-tool.html?redirect=/trading/interest-rates/countdown-to-fomc.html')
         'https://www.cmegroup.com/markets/interest-rates/cme-fedwatch-tool.html?redirect=/trading/interest-rates/countdown-to-fomc.html')
     sleep(2)
     sleep(2)
+    agent = driver.execute_script("return navigator.userAgent")
+    print(agent)
     text = driver.find_element(By.XPATH, '//*[@id="page_default_sections"]/div/div/div/div/div/p[1]/span')
     text = driver.find_element(By.XPATH, '//*[@id="page_default_sections"]/div/div/div/div/div/p[1]/span')
     print("网页中段,文本内容:")
     print("网页中段,文本内容:")
     print(text.text)
     print(text.text)