selenium爬虫无法访问部分网站

求问关于python selenium爬虫无法访问特定网站的问题

网站:http://credit.customs.gov.cn/

此网站是企业海关报备信息的网站,用selenium的进行爬虫打开此网站却是白板一片,但是手动输入到浏览器却有结果

可以排除是版本问题、代码问题、以及网站输入问题,个人判断是网站的问题?因为我输入其他网站是可以打开的,唯独这个网站无法打开。

img

求帮助解答!感谢!

说明被识别到了,可以学习一下selenium反爬知识,我加了如下代码可以打开页面

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
opt = Options()
opt.add_argument("--disable-blink-features=AutomationControlled")
web = webdriver.Chrome(options=opt)

如有帮助,敬请采纳,你的采纳是我前进的动力,O(∩_∩)O谢谢!!!!!!!!
Chrome不行就上firefox吧
已验证可行

img

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
# 浏览器路径
binary = FirefoxBinary('你的火狐浏览器路径files/firefox')  
# 驱动路径
browser = webdriver.Firefox(executable_path="你的geckodriver路径/geckodriver", firefox_binary=binary)
browser.get('http://credit.customs.gov.cn/')

https://blog.csdn.net/chinaherolts2008/article/details/112852791
问题应该出在webdriver上, 网站检测到了标识, 看看这个文章.
还有这个
https://blog.csdn.net/Bejpse/article/details/123300206

试试这个
https://blog.csdn.net/dslkfajoaijfdoj/article/details/109146051



from selenium.webdriver.chrome.options import Options
from selenium import webdriver

option = Options()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=option)

url = 'http://credit.customs.gov.cn/'
driver.get(url=url)
driver.maximize_window()

input()


我也遇到过这个问题,原因是你打开了多个浏览器窗口,之前的窗口存在cookie 未清空,导致和新打开的窗口cookie冲突了。先使用driver.delete_all_cookies()清空一下cookie再发起请求就行。

你可以参考下这篇文章:selenium设置代理后无法访问网页问题解决

这个大哥的可以试试:https://blog.csdn.net/dslkfajoaijfdoj/article/details/109146051

我试了一下我写的这段代码可以加载成功页面,在使用之前你需要额外下载一个文件:stealth.min.js
下载地址:https://github.com/cloud-org/stealth.min.js/
或者用我百度网盘的文件:
链接:https://pan.baidu.com/s/103qgkV2mo6XfRMQjF3MFtg
提取码:1234

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.common.keys import Keys


options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument('--disable-blink-features=AutomationControlled')
with open('stealth.min.js') as f:
    js = f.read()

driver_path = r'F:\Python-项目\weixing\Scripts\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path,chrome_options = options)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": js
})


time.sleep(2)
driver.get('http://credit.customs.gov.cn/')

可能被检测出来了,试着使用无头浏览器

被检测了

这个亲测有效

from selenium.webdriver.chrome.options import Options
from selenium import webdriver

option = Options()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=option,executable_path='C:/img/chromedriver.exe')

url = 'http://credit.customs.gov.cn/'
driver.get(url=url)
driver.maximize_window()