的超时webdriver.PhantomJS在python中?

2024-04-19 14:52:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我只使用selenium python。在

当我使用webdriver.Firefox()时,我可以得到结果。 当我使用webdriver.PhantomJS()时,结果无法返回(脚本挂起)。在

有人能帮我吗?在

browser = webdriver.PhantomJS(executable_path='./lib/phantomjs/phantomjs')
url = "http://aminer.org/search/jie%20tang"
browser.get(url)

Tags: pathorgbrowser脚本httpurlsearchlib
1条回答
网友
1楼 · 发布于 2024-04-19 14:52:10

我复制了这个问题,也看到了悬挂的幻影。我尝试了多种解决方法(包括加载禁用了web安全性的“https”url;尝试不加载图像、增加脚本和页面加载超时、更新phantomjs等),但直到现在还没有使它起作用。在

这里有一种不涉及硒的替代方法-使用胺基API。在

以下是如何使用^{}获得相同的搜索结果:

import requests


url = 'http://storeland.ru/user/login'
api_url = 'https://api.aminer.org/api/search/people'
with requests.Session() as session:
    session.get(url)

    params = {
        'query': 'jie+tang',
        'size': '20',
        'sort': 'relevance',
        # 'offset': 20  # set offset for pagination
    }
    response = session.get(api_url, params=params)
    for item in response.json()['result']:
        print item['name']

打印(搜索结果的第一页):

^{pr2}$

相关问题 更多 >