Python Monitor Water Falls(1)Ideas from Scrapy and Twisted
>python -V
Python 2.7.13
>pip --version
pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (python 2.7)
Make sure we have the Scrapy Installed
>pip install scrapy
>pip install scrapyd
>scrapy version
Scrapy 1.4.0
>scrapyd --version
twistd (the Twisted daemon) 17.5.0
Visit the Web Page https://hydromet.lcra.org/riverreport
Basic method to load the content open_url.py
from selenium import webdriver
path2phantom = '/opt/phantomjs/bin/phantomjs'
browser = webdriver.PhantomJS(path2phantom)
browser.get('https://hydromet.lcra.org/riverreport')
tables = browser.find_elements_by_css_selector('table.table-condensed')
tbody = tables[5].find_element_by_tag_name("tbody")
for row in tbody.find_elements_by_tag_name("tr"):
cells = row.find_elements_by_tag_name("td")
if(cells[0].text == 'Marble Falls (Starcke)'):
print cells[1].text
browser.quit()
By executing the command directly, it will tell you the content
>python open_url.py
Jan 21 2018: No releases
Twisted RESTful
download the latest version
>wget https://twistedmatrix.com/Releases/Twisted/17.9/Twisted-17.9.0.tar.bz2
Unzip and go into that directory
>python setup.py install
Check the version
>>>> import twisted
>>> print twisted.version
[Twisted, version 17.5.0]
Maybe long time ago, I already install 17.5.0
This RESTful library is a little old
https://github.com/iancmcc/txrestapi
RESTful with twisted
BookAPI.py
from txrestapi.methods import GET, POST, PUT, ALL, DELETE
from txrestapi.resource import APIResource
import json
class BookResource(APIResource):
@GET('^/book/(?P<id>[^/]+)')
def getBook(self, request, id):
return 'Pick up one book with id %s' % id
@GET('^/book/')
def books(self,request):
return "books"
@PUT('^/book/(?P<id>[^/]+)')
def updateBook(self,request, id):
book = json.loads(request.content.read())
book['id'] = id
return json.dumps(book)
@POST('^/book/')
def saveBook(self, request):
book = json.loads(request.content.read())
book['id'] = 1
return json.dumps(book)
@DELETE('^/book/(?P<id>[^/]+)')
def deleteBook(self,request,id):
return "Delete book with id %s" % id
@ALL('^/')
def default_view(self, request):
return "I fail to match other URLs."
RestAPI.py
from twisted.web.resource import Resource
from twisted.web.server import Site
from twisted.internet import reactor
from BookAPI import BookResource
bookResource = BookResource()
rootResource = Resource()
rootResource.putChild("book", bookResource)
site = Site(rootResource, timeout=None)
reactor.listenTCP(8888,site)
reactor.run()
References:
https://scrapy.org/
https://hydromet.lcra.org/riverreport
Twisted
http://sillycat.iteye.com/blog/2243749
http://sillycat.iteye.com/blog/2243775
http://sillycat.iteye.com/blog/2244167
http://sillycat.iteye.com/blog/2244169
python json
https://code.tutsplus.com/tutorials/how-to-work-with-json-data-using-python--cms-25758
分享到:
相关推荐
本资源中利用Frank-Wolfe算法求解了SiouxFalls网络的交通分配结果(UE用户均衡结果,即没有用户可以通过单方面改变出行路径从而降低出行费用)。网络基本信息如txt文件所示,路阻函数采用了经典美国联邦公路局BPR...
《PyPI官网下载:探索Python库“gravity_falls”》 在Python的生态系统中,PyPI(Python Package Index)扮演着至关重要的角色,它是全球最大的Python软件仓库,为开发者提供了无数的开源库和模块。本篇文章将围绕...
Linux and the Unix Philosophy falls squarely between the softer texts on iterative software design and project management and the “how to” technical texts. Thus far, no one has come out with a book ...
Screen Mountain Waterfall 3D Screensaver will reveal a breathtaking spectacle of the mountain falls away from civilization. Relaxing music and sounds of wild nature will kill you away from the city ...
### Python中的正则表达式详解 #### 一、引言 正则表达式(Regular Expression),简称regex或regexp,是一种非常强大的文本处理工具。它能够帮助我们高效地完成字符串的搜索、匹配、替换等操作。在Python编程语言...
falls below the noise level and this simple receiver becomes a viable option. The tradeoff between the energy efficiency (as measured in bits/J) and spectral efficiency (as measured in bits/channel ...
Gravitty Falls.exe
Our air, water, and soil are suffering from severe pollution—a pressing environmental challenge of our time. Contaminated air not only deteriorates our health, causing respiratory diseases and ...
No matter what medium you use to deliver content, if the visual design fails, the experience falls flat. Meaningful graphics and a compelling visual design supercharge instruction, training, and ...
Learn how SignalR uses Websockets when supported by the browser and the server and falls back to other techniques and technologies when it is not Use the simple ASP.NET API in SignalR for creating ...
Based on the given information from the file "T-REC-G.709.1-202005-I!Cor1!PDF-E.pdf," this document pertains to the International Telecommunication Union (ITU) standards and specifically focuses on ...
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>. Please note that the examples are not production ...
I argue on the one hand that its emphasis on pragmatism falls short of providing a reflective and principled methodology, and that on the other hand conceptualism is doomed by its neglect of reality....
标题“Get the Day of Week that a Day Falls On”暗示了一个编程任务,即获取特定日期是星期几。这个功能在各种应用程序中都很常见,比如日历应用或者时间管理工具。让我们深入探讨一下相关知识点。 首先,我们...
One clear editorial screwup is apparent where Chapter 1 calls this "pre-test" and all other chapters call it "self-test." That's why I say "rush job". I found myself confused with the authors ...
Alan Walker All Falls Down.mp3
Students need to analyze the motion of the chain as it falls, taking into account the tension and the changing gravitational potential energy. - **Cat and Mouse Tug of War (Moscow Phys-Tech, MIT)**:...
Module Overview 1 Lesson 1: Memory 3 Lesson 2: I/O 73 Lesson 3: CPU 111 Module 3: Troubleshooting Server Performance Module Overview Troubleshooting server performance-based support ...