文件下载脚本(urllib python)和正则表达式
多个小问题。
1)file.name的命令是什么?我知道它存在......当我执行 file.info() 时,它出现在 filename="blah blah" 下,所以我尝试了 file.info()[index] 但解释器对此发出了嘶嘶声。我在文档中的任何地方都找不到它的对象类型 HTTPResponse。
我有
#Download file
print("downloading")
file = urllib.request.urlopen(URL + "/index.php?app=downloads&module=display§ion=download&do=confirm_download&id=881"))
#Write file
out = open(SAVE_FOLDER + file.name , "wb") ###file.name DOESNTWORK
out.write(file)
out.close()
3) #for info 我正在登录 invision 电源板。 因此,为了了解如何登录该网站,我使用 wire shark 并找到了它发送到该网站的 http 请求。它有一个基于行的文本数据部分,表示引用者 = blah blah blah。所以我知道我必须将这些数据发送到服务器才能登录。但它不起作用,所以我用谷歌搜索了一些,偶然发现我还必须发送用户名和密码。即使引用网址中无论如何都有用户名和密码。
所以...我的问题。我怎么会发现数据必须是这样的,
values = "username" : USERNAME,
"password" : PASSWORD,
"referer" : "http%3A%2F%2FsomeURL.com%2Findex.php%3F&username=" + USERNAME + "&password=" + PASSWORD + "&rememberMe=1"
而不是像我一样偶然发现它,因为wireshark上的POST消息中只有引用者。
希望这就是一切。其他问题可能有一些重叠,对此感到抱歉。 预先感谢
编辑:找出问题2。
Multiple small problems.
1) Whats the command for file.name? I know it exists... when I do file.info() the it appears under filename="blah blah" so i tried file.info()[index] but interpreter throws a hissy fit about that. I cant find it anywhere in the docs for the type of object it is, HTTPResponse.
I have
#Download file
print("downloading")
file = urllib.request.urlopen(URL + "/index.php?app=downloads&module=display§ion=download&do=confirm_download&id=881"))
#Write file
out = open(SAVE_FOLDER + file.name , "wb") ###file.name DOESNTWORK
out.write(file)
out.close()
3) #for info im logging into an invision power board.
So to find out how to log into the site, I used wire shark and found the http request that it sends to the site. It had a linebased text data part that said referer = blah blah blah. So I knew I had to send that data into the server to log in. But it didn't work, so I googled some and found by accident that I also had to send in a username and password. Even though the referer url thing HAS the user name and password in it anyways.
SO... my question. How would I have found out that the data had to be
values = "username" : USERNAME,
"password" : PASSWORD,
"referer" : "http%3A%2F%2FsomeURL.com%2Findex.php%3F&username=" + USERNAME + "&password=" + PASSWORD + "&rememberMe=1"
instead of finding it on accident like I did since the POST message on wireshark only had referer in it.
Hopefully that's everything. There might be some overlap for it in other questions, so sorry about that.
Thanks in advance
edit: figure out problem 2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
URL 没有名称。您获得的最接近的是 URL 本身,您可以使用 file.geturl() 获得它。
您可以通过查看登录表单及其字段来发现这一点。引用网址在这里很可能是无关紧要的。
URL's does not have names. The closest you get is the URL itself, which you can get with file.geturl().
You would have found that out by looking at the login form and the fields it has. The referrer is most likely irrelevant here.