Mat*_*ens 7 python selenium pythonanywhere selenium-webdriver python-3.5
我的理解是pythonanywhere支持无头的Firefox浏览器但你需要
from pyvirtualdisplay import Display
Run Code Online (Sandbox Code Playgroud)
所以你可以使用连接
with Display():
while True:
try:
driver = webdriver.Firefox()
break
except:
time.sleep(3)
Run Code Online (Sandbox Code Playgroud)
我连接得很好.但是,在我开始使用驱动程序之后
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 …
Run Code Online (Sandbox Code Playgroud)
我过了一会儿就得到了这个错误
对于它的价值,这段代码在我的本地机器上运行得非常好.此外,我是付费会员,所以不应该有白名单问题.
最近我了解到雅虎已经阻止python在运行任何网络抓取脚本的地方.我认为所有AWS服务器和使用它们的人都是如此,但我并不是100%肯定这一点.我希望这有助于任何遇到这个问题的人.
https://www.pythonanywhere.com/forums/topic/5724/#id_post_52307
| 归档时间: |
|
| 查看次数: |
340 次 |
| 最近记录: |