我只使用selenium-python。
当我使用webdriver.Firefox()
时,我可以获得结果。
当我使用webdriver.PhantomJS()
时,无法返回结果(脚本挂起)。
谁能帮我吗?
browser = webdriver.PhantomJS(executable_path='./lib/phantomjs/phantomjs')
url = "http://aminer.org/search/jie%20tang"
browser.get(url)
最佳答案
我已经重现了这个问题,并且也看到了挂起的 PhantomJS。我已经尝试了多种解决方法(包括在禁用网络安全的情况下加载“https”url;尝试不加载图像、增加脚本和页面加载超时、更新 phantomjs 等),但到目前为止还没有使其工作。
这里有一种不涉及 Selenium 的替代方法 - 使用 AMiner API。
以下是如何使用 requests
获得相同的搜索结果:
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']
打印(搜索结果的第一页):
Zhu Jie-Tang
Jie-Tang Zhao
...
Jie-Tang Wu
Tian Jietang
关于python - python 中的 webdriver.PhantomJS 超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30623004/