当前位置: 首页>>代码示例>>Python>>正文


Python URL.open方法代码示例

本文整理汇总了Python中pattern.web.URL.open方法的典型用法代码示例。如果您正苦于以下问题:Python URL.open方法的具体用法?Python URL.open怎么用?Python URL.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pattern.web.URL的用法示例。

在下文中一共展示了URL.open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pattern.web import URL [as 别名]
# 或者: from pattern.web.URL import open [as 别名]
def main():
	table = Datasheet()
	tel = ''
	street = ''
	locality = ''
	title = ''
	for i in range(3):
		page = i+1
		url = 	URL("http://torino.paginegialle.it/pgol/4-veterinari/3-torino/p-%s?mr=50" % page)
		print "collecting from %s" % url
		connection = url.open()
		doc = Document( connection.read() )
		items = doc.by_class('item_sx')
		row = []
		for j, item in enumerate(items):
			divs = item.by_class('address')
			try:	
				title = item.by_class('item_head')[0].by_tag('a')[0].content
			except IndexError, e:
				print >> sys.stderr, "%s" % j, e
				pass
			for z, div in enumerate(divs):
				if div != None:
					try:
						street = div.by_class('street-address')[0].content
						locality = div.by_class('locality')[0].content
						tel = div.by_class('tel')[0].by_class('value')[0].content
					except IndexError, e:
						print >> sys.stderr, "%s" % z, e
						pass
					save = "%s, %s %s, %s \n" % ( plaintext(title), plaintext(street).replace(",", ""), plaintext(locality).replace('(TO)', ''), plaintext(tel).replace(",", "") )
					print >> sys.stderr, save
					row.append(save)
开发者ID:rogopag,项目名称:cityhelper,代码行数:35,代码来源:grabv.py


示例2: main

# 需要导入模块: from pattern.web import URL [as 别名]
# 或者: from pattern.web.URL import open [as 别名]
def main():
	table = Datasheet()

	for cap in CAPS:
		url = 	URL("http://www.comuni-italiani.it/001/272/farmacie/cap%s.html" % cap)
		connection = url.open()
		doc = Document( connection.read() )
		items = doc.by_tag("table")
		row = []
		for j, td in enumerate( items[5].by_tag('td') ):
			strcap = "%s, Telefono:" % cap
			save = "%s" % plaintext(td.content).replace('\n', ',', 3).replace("Telefono:", strcap).replace(";", "").replace("Partita Iva", ",Partita Iva") + "\n"
			if save != None:
				row.append( save )
		table.append( row )
		print  "%s ----------------------------------------------------------------------------" % str(j)
		
	table.save("files/farmacie_torino.txt")
开发者ID:rogopag,项目名称:cityhelper,代码行数:20,代码来源:grabfarm.py


示例3: main

# 需要导入模块: from pattern.web import URL [as 别名]
# 或者: from pattern.web.URL import open [as 别名]
def main():
	table = Datasheet()

	url = 	URL("http://www.comuniecitta.it/torino/elenco-ospedali-di-torino.html")
	connection = url.open()
	doc = Document( connection.read() )
	items = doc.by_class('ulamm')[1:]
	row = []
	for ul in items:
		li = ul.by_tag('li')
		kind = plaintext(ul.previous.content)
		for el in li:
			if el != None:
				save = "%s, %s \n" % ( plaintext(el.content).replace('\n', ','), kind, )
				row.append(save)
	table.append( row )
		
	table.save("files/h_torino.txt")
开发者ID:rogopag,项目名称:cityhelper,代码行数:20,代码来源:grabh.py


示例4: URL

# 需要导入模块: from pattern.web import URL [as 别名]
# 或者: from pattern.web.URL import open [as 别名]
# Tweet to post:
tweet = "avalancheddar"

# The API for posting is described here:
# # https://dev.twitter.com/rest/reference/post/statuses/update
url = URL("https://api.twitter.com/1.1/statuses/update.json", method="post", query={"status": tweet})

# We'll use the Twitter._authenticate() method to authenticate ourselves 
# as @ccpattern (so the new tweet will appear on @ccpattern's page):
twitter = Twitter(license=ccpattern)
url = twitter._authenticate(url)

try:
    # Send the post request.
    url.open()
except Exception as e:
    print e
    print e.src
    print e.src.read()
    
# To create your own Twitter bot:

# 1) You need a new e-mail address for the bot (e.g., gmail.com).
# 2) You need a new Twitter account.
# 3) Verify the Twitter account from the e-mail they send you.
# 4) Verify the Twitter account with a mobile phone number (this is mandatory): 
#   https://support.twitter.com/articles/110250-adding-your-phone-number-to-your-account
# 5) While logged in in the new account, create a Twitter App:
#   https://apps.twitter.com/app/new
# 6) Modify the app's permissions to "read & write".
开发者ID:OAlm,项目名称:the_stromberg_stories,代码行数:32,代码来源:tweet.py



注:本文中的pattern.web.URL.open方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。