开发者

File downloading script (urllib python) and regular expressions

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&section=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 t开发者_如何转开发he 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.


  1. URL's does not have names. The closest you get is the URL itself, which you can get with file.geturl().

  2. You would have found that out by looking at the login form and the fields it has. The referrer is most likely irrelevant here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜