Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import time
- from selenium import webdriver
- url='http://www.nhc.gov.cn/wjw/gfxwjj/list.shtml'
- 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"}
- r=requests.get(url, headers=headers, timeout=50)
- r.encoding='utf-8'
- print(r.status_code)
- # 不自動關閉瀏覽器
- option = webdriver.ChromeOptions()
- option.add_experimental_option("detach", True)
- web=webdriver.Chrome('chromedriver.exe')
- # 將option作為引數新增到Chrome中
- web = webdriver.Chrome('chromedriver.exe', chrome_options=option)
- web.get(url, headers=headers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement