【发布时间】:2019-02-20 13:02:33
【问题描述】:
我的理解是pythonanywhere支持无头火狐浏览器但你需要
from pyvirtualdisplay import Display
所以你可以使用连接
with Display():
while True:
try:
driver = webdriver.Firefox()
break
except:
time.sleep(3)
而且我连接得很好。但是,在我开始使用驱动程序后,
with Display():
while True:
try:
driver = webdriver.Firefox()
break
except:
time.sleep(3)
wb=load_workbook(r'/home/hoozits728/mutual_fund_tracker/Mutual_Fund_Tracker.xlsx')
ws=wb.get_sheet_by_name('Tactical')
for i in range(3, ws.max_row+1):
if ws.cell(row=i,column=2).value is not None:
driver.get('https://finance.yahoo.com/quote/' + ws.cell(row=i,column=2).value + '/performance?ltr=1')
oneyear=driver.find_element_by_css_selector('#Col1-0-Performance-Proxy > section > div:nth-child(2) > div > div:nth-child(5) > span:nth-child(2)').text
threeyear=driver.find_element_by_css_selector('#Col1-0-Performance-Proxy > section > div:nth-of-type(2) > div > div:nth-of-type(6) > span:nth-of-type(2)').text
fiveyear=driver.find_element_by_css_selector('#Col1-0-Performance-Proxy > section > div:nth-of-type(2) > div > div:nth-of-type(7) > span:nth-of-type(2)').text
ws.cell(row=i,column=10).value=oneyear
ws.cell(row=i,column=11).value=threeyear
ws.cell(row=i,column=12).value=fiveyear
… and so on …
过了一会儿,我收到了这个错误
不管怎样,这段代码在我的本地机器上运行良好。另外,我是付费会员,所以应该没有白名单问题。
【问题讨论】:
-
使用错误堆栈跟踪更新问题
-
@New 贡献者 你能看到图片吗?我无法从 pythonanywhere 控制台一次复制每一行。
-
听起来浏览器崩溃了;也许这与页面内容有关?如果你点击不同的 URL,比如
https://www.google.com/,会发生什么? -
@GilesThomas 你搞定了!显然我的网址有问题;但是,直接在浏览器中输入 url 会产生一个正确的网页。这是代码解析为:finance.yahoo.com/quote/USCBX/performance?ltr=1
-
我正要回复,但我看到你已经在下面的答案中找到了问题——已经投票了:-)
标签: python selenium selenium-webdriver python-3.5 pythonanywhere