The first script of Python is written

Source: Internet
Author: User

The first Python script I wrote was a data that was used to extract dynamic Web pages, to do the calculations, and to commit.

The requirements of the Web page are obvious, which is to give a formula. Ask the submitter to submit it within 1.5S. Because this is too large, so direct calculation? does not exist.

The functionality of the script is reflected at this time.

I have a lot of problems in the course of this problem. The first is my writing platform Pycharm, because this is my first Python script, also my first program, so the use of pycharm is quite unfamiliar. And then it's when you reference the requests library. The above tip does not have this library, but I have already used PIP install requests installed AH. Unfortunately, the use of pycharm is not the case, but in its setting inside the installation. This is the first question that I have solved.

Then is the use of the Requests.get (URL) to obtain the data, and then converted to the text format, that is, the content of the page is converted into the form of characters, the following step is actually quite simple, but also natural, is how to extract the characters, I was first used

NPos = R.text.index (' exp ')
Print (NPos)

That is to find the corresponding ID is the location of the number of exp.

M1=M[515:523]
M2=M[524:532]
M3=M[533:540]
M4=M[541:549]

Extracted the string corresponding to these numbers,

Then you use the NUM () function to pick out the numbers (letters) in these strings,

then use INT () to convert the character variable into a number, otherwise the mathematical calculation is not possible.

Calculate it out answer

This is also the corresponding variable of the direction of the submission, the following is the biggest problem I encountered, that is, I started at the time of submission with the construction of a dictionary

com={' answer ': answer}

Succeed=requests.get (url,params=com)

Print (Succeed.text)

I thought it was over,

But I didn't take into account that the value of the cookie that was brought by the two commits is different (the seniors say that the package that uses the mock grab can crawl the script you wrote using the proxies module), so this is a re-request, that is, the data requested for the first time has

Unlike the data from this request, this is a two-time stand-alone request.

Then, the Final solution is ...

Use requests at the beginning. The session () can then be kept in a session (), so you can use frist=requests directly in the beginning. Session ()

And then it's natural to switch to the inside that contains the flag. This problem is finally finished.

The first script of Python is written

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.