【发布时间】:2017-03-10 09:54:45
【问题描述】:
我无法抓取使用 react.js 编程的主页 http://www.jobs.ch。
我想在搜索框中输入术语Business 并执行搜索。
Dryscrape 为另一个不是 react.js 页面的示例工作。
如何在此搜索字段中输入术语 Business?
我的脚本执行时的错误信息:
ubuntu@ubuntu:~/scripts$ python jobs.py
Traceback (most recent call last):
File "jobs.py", line 30, in <module>
name.set("Business")
AttributeError: 'NoneType' object has no attribute 'set'
这是我的脚本:
#We will write a Python script to visit a webpage. Fill in the form and submit the form.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import dryscrape
# make sure you have xvfb installed
dryscrape.start_xvfb()
root_url = 'http://www.jobs.ch/en/vacancies/'
if __name__ == '__main__':
# set up a web scraping session
session = dryscrape.Session(base_url = root_url)
# we don't need images
session.set_attribute('auto_load_images', False)
session.set_header('User-agent', 'Google Chrome')
# visit exact webpage which is the form in this example
session.visit('http://www.jobs.ch/en/vacancies/')
# fill in the form by taking ID of field from webdev tool
#name = session.at_xpath('//*[@data-reactid="107]')
name = session.at_xpath('//*[@data-reactid="107"]//*[@class="search-input col-sm-4 col-md-5"]')
name.set("Business")
# submit form
name.form().submit()
# save a screenshot of the web page
session.render("jobs.png")
print("Session rendered successfully!")
【问题讨论】:
标签: python web-scraping dryscrape