python - TimeoutError: [WinError 10060] 连接尝试失败
问题描述
TimeoutError: [WinError 10060] 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应
我做了我能想到的一切来解决这个问题,但也许我没有完全理解这个错误。请帮帮我。
这是代码和链接。
import urllib.request
import requests
link = "https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbolCode=242&symbol=RELIANCE&symbol=RELIANCE&instrument=OPTSTK&date=-segmentLink=17&segmentLink=17"
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
request = urllib.request.Request(link,headers={'User-Agent': user_agent})
response = urllib.request.urlopen(request)
html = response.read()
print(html)
解决方案
改用selenium
:
from selenium import webdriver
import os
browser = webdriver.Chrome(executable_path=os.path.abspath(os.getcwd()) + "/chromedriver")
link = "https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbolCode=242&symbol=RELIANCE&symbol=RELIANCE&instrument=OPTSTK&date=-&segmentLink=17&segmentLink=17"
browser.get(link)
context = browser.page_source
推荐阅读
- azure - C# 中用于使用 Azure API 管理删除缓存的 SDK 的可用性
- angularjs - AngularJS - 使用 .components() 与使用 TypeScript 定义组件
- apache - 如果目录显示为可写,为什么“该目录不可被 Web 进程写入”?
- asp.net-mvc - Kentico 12 PageBuilder 缺少参考
- matrix - 使用 Julia 将未格式化的 FORTRAN 文件读入多维数组
- reactjs - 单击卡片时如何路由到具有特定卡片详细信息的页面?
- javascript - 根据范围返回数组中的对象
- c++ - 为什么必须在线程销毁之前调用 join() 或 detach() ?
- c# - 未找到命令 dotnet ef
- arrays - 在二进制数组中查找集群组