Advertisement
ShawnHsia

failurl

Apr 17th, 2022 (edited)
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import time
  4. from selenium import webdriver
  5.  
  6. url='http://www.nhc.gov.cn/wjw/gfxwjj/list.shtml'
  7. headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.46"}
  8.  
  9. r=requests.get(url, headers=headers, timeout=50)
  10. r.encoding='utf-8'
  11. print(r.status_code)
  12.  
  13. # 不自動關閉瀏覽器
  14. option = webdriver.ChromeOptions()
  15. option.add_experimental_option("detach", True)
  16. web=webdriver.Chrome('chromedriver.exe')
  17. # 將option作為引數新增到Chrome中
  18. web = webdriver.Chrome('chromedriver.exe', chrome_options=option)
  19. web.get(url, headers=headers)
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement