使用python+chromedriver+selenium爬取某网站,因为需要输入,查询项目的编号和验证码,因为要查三万多条所以就想写个爬虫解决
网址如下:
http://sq.nmpa.gov.cn/datasearch_nmpa/schedule/search.jsp?tableId=43&tableName=TABLE43&columnName=COLUMN464,COLUMN475&title=%D2%A9%C6%B7%D7%A2%B2%E1%BD%F8%B6%C8%B2%E9%D1%AF
chrome版本:87.0.4280.88
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
option = webdriver.ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
为了把window.navigator.webdriver的参数改成undifine,我添加了option
browser = webdriver.Chrome(options=option)
browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",{
"source":"""
Object.defineProperty(navigator,'webdriver',{
get: () => undefined
})
"""
})
用webdriver打开目标页面
url = 'http://sq.nmpa.gov.cn/datasearch_nmpa/schedule/search.jsp?tableId=43&tableName=TABLE43&columnName=COLUMN464,COLUMN475&title=%D2%A9%C6%B7%D7%A2%B2%E1%BD%F8%B6%C8%B2%E9%D1%AF'
browser.get(url)
找到【查询】按钮的xpath
xpath = 'html/body/div[3]/div[2]/table[1]/tbody/tr/td/form/table/tbody/tr[2]/td/input[6]'
到这步为止,我点击查询按钮还是正常的,如果输错验证码会有弹窗,如果输入对了就会进入要查询的数据的详情页面。但是只要执行下面这句话
locat = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, xpath)))
再点击【查询】就没有任何反应,弹窗也不出来了,即使受理号和验证码输入正确再点【查询】也没有任何反应,但是点击验证码的图片,验证码还是可以更换的,请问这种情况该如何解决呢?