代码如下:
[code#coding:utf-8
import webbrowser as web
url = raw_input('请输入您要刷博的网址:') #定义的变量url
c = 0
while c <= 9:
web.open_new_tab('url') #需要在这里引入这个变量!
c = c + 1
][/code]
目的,当我输入一个网址的时候,就打开这个网址。可是web.open_new_tab后面不知道如何把这个变量正确引入。
问:我应该如何实现当我在终端输入一个网址,就打开我所输入的网站?
我应该如何引用这个url变量呢?
- 九天星
- 帖子: 1440
- 注册时间: 2007-07-14 20:45
- vickycq
- 帖子: 4507
- 注册时间: 2011-03-20 13:12
- 系统: Debian
- 来自: 山东省寿光县
- 联系:
Re: 我应该如何引用这个url变量呢?
尝试移除单引号九天星 写了:web.open_new_tab('url')
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
欢迎所有 Debian GNU/Linux 用户
- 九天星
- 帖子: 1440
- 注册时间: 2007-07-14 20:45
Re: 我应该如何引用这个url变量呢?
vickycq 写了:尝试移除单引号九天星 写了:web.open_new_tab('url')
我试过,不行,似乎取绝于这个模块包含有的功能。。。。可能是这个模块没这个功能。
- 九天星
- 帖子: 1440
- 注册时间: 2007-07-14 20:45
Re: 我应该如何引用这个url变量呢?
从我搜到的这行原码看到又好像可以
代码: 全选
def show_plot(html, saveHTML, show, async=False):
if show == 'inline':
from IPython.display import HTML
return HTML(html)
elif show == 'tab':
print 'Opening new tab...'
if async:
address = url(async)
webbrowser.open_new_tab(address)
else:
webbrowser.open_new_tab('file://' + os.path.realpath(saveHTML))
elif show == 'window':
print 'Trying to open a window. If this fails we will open a tab...'
if async:
address = url(async) #这个用法不就类似吗?
webbrowser.open_new(address) #这个变量地址引用到这里来了!
else:
webbrowser.open_new('file://' + os.path.realpath(saveHTML))
elif show == 'none':
pass
- 九天星
- 帖子: 1440
- 注册时间: 2007-07-14 20:45
Re: 我应该如何引用这个url变量呢?
可以了,我将变量名变成address就可以了,不过输入的网址要加入https://,于是我又调整了一下,使用web.open_new_tab(r'http://'+(address)),就可以了。
- vickycq
- 帖子: 4507
- 注册时间: 2011-03-20 13:12
- 系统: Debian
- 来自: 山东省寿光县
- 联系:
Re: 我应该如何引用这个url变量呢?
或与此无关九天星 写了:可以了,我将变量名变成address就可以了
是的。weibo.com 是域名,http://weibo.com 是 URL(网址)九天星 写了:不过输入的网址要加入https://,于是我又调整了一下
字符串前不加 r 试试。因理论上 r 只影响反斜杠 '\' 的解读九天星 写了:使用web.open_new_tab(r'http://'+(address)),就可以了。
参考
https://en.wikipedia.org/wiki/URL
https://en.wikipedia.org/wiki/Domain_name
https://docs.python.org/2/library/webbrowser.html
https://docs.python.org/2/reference/lex ... g-literals
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
欢迎所有 Debian GNU/Linux 用户
- 九天星
- 帖子: 1440
- 注册时间: 2007-07-14 20:45
Re: 我应该如何引用这个url变量呢?
[/quote]
字符串前不加 r 试试。因理论上 r 只影响反斜杠 '\' 的解读
[/quote]
如果字符串前不加r的话,执行结果如下。
加r的执行结果如下:
结论,上面的错误提示我没看懂,看来还是应该加。
字符串前不加 r 试试。因理论上 r 只影响反斜杠 '\' 的解读
[/quote]
如果字符串前不加r的话,执行结果如下。
代码: 全选
python shuaboqi.py
请输入您要刷博的网址:www.baidu.com
请输入您要刷博的次数:10
[2474:2474:1019/144318:ERROR:logging.h(808)] Failed to call method: org.freedesktop.DBus.ObjectManager.GetManagedObjects: object_path= /: org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist
[2474:2474:1019/144318:ERROR:logging.h(808)] Failed to call method: org.freedesktop.DBus.ObjectManager.GetManagedObjects: object_path= /: org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
wlp2s0@wlp2s0-computer:~/文档/python$ [2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
[2474:2474:1019/144327:ERROR:zygote_host_impl_linux.cc(543)] Failed to send GetTerminationStatus message to zygote
加r的执行结果如下:
代码: 全选
wlp2s0@wlp2s0-computer:~/文档/python$ python shuaboqi.py
请输入您要刷博的网址:www.baidu.com
请输入您要刷博的次数:10
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
已在现有的浏览器会话中创建新的窗口。
结论,上面的错误提示我没看懂,看来还是应该加。
- 九天星
- 帖子: 1440
- 注册时间: 2007-07-14 20:45
Re: 我应该如何引用这个url变量呢?
最后的成品
比如说我想保护这段代码,不让别人看到源码我应该怎么做呢?
代码: 全选
#coding:utf-8
import webbrowser as web
import time
import os
print(""" \033[1;36m
┌══════════════════════════════════════════════════════════════┐
█ █
█ Welcome to use the brush █
█ #零 █
█ █
█ Weixin:xfiles_sky E-mail:wlp2s0@yandex.com █
└══════════════════════════════════════════════════════════════┘ \033[1;m""")
address = raw_input('请输入您要刷的网址:')
b = int(raw_input('请输入您要刷博的次数:')) - 1
c = 0
while c <= b:
web.open_new_tab(r'https://'+(address))
c = c + 1
time.sleep(1)
else:
os.system('killall chrome')
print ('刷博成功完成!')
比如说我想保护这段代码,不让别人看到源码我应该怎么做呢?