There are three reasons why I decided to record what I learned.
Since it was Markdown notation with some experience on GitHub, I checked the notation as a review. Since this is the first article, I used as many notations as possible.
Even though I'm new to Python, I wondered if I could start scraping suddenly. However, after studying programming for two years at university, I couldn't continue studying from scratch about variables, functions, branches, etc., so I didn't have to do scraping and machine learning to learn Python grammar. I decided to study at the same time. The following is a very basic content, but I will summarize what I learned today.
It was a comment-out description method different from the experienced C, Java, and Swift.
#
are commented out. (After #
, leave a space before writing a comment)# One line comment out
" ""
(3 double quotes) or'''
(3 single quotes) are commented out."""
By double quotes
Comment out multiple lines
"""
'''
By single quote
Comment out multiple lines
'''
A description method similar to the Java extension for statement
num = [0, 1, 2, 3]
#Loop statement
for a in num:
print(a)
Execution result
0 1 2 3
In Python, function names are treated in the same way as variable names. Useful when defining small functions.
bai_print = lambda x: print(x*2)
bai(2)
bai(10)
Execution result
4 20
I learned scraping using ʻurllib`. Below is a summary of the functions in the urllib library that I learned today and their usage examples.
import urllib.request as req
import urllib.parse as par
url = "https://uta.pw/shodou/img/28/214.png "
savename = "test.png "
# urlretrieve (URL of file, file name of save destination)
# Function to download a file on the web
# https://uta.pw/shodou/img/28/214.pngにあるpngファイルがtest.pngという名前で保存される
req.urlretrive(url, savename)
# urlopen (file URL)
# Read data with read (), a function that opens URL resources
# Files on the web are saved in Python memory
mem = req.urlopen(url).read()
# urlencode (parameter to convert to URL)
# Create a query from parameters and create a URL for the request
# https://api.aoikujira.com/zip/xml/get.php?fmt=xml&zn=1500042というURLが生成される
API = "https://api.aoikujira.com/zip/xml/get.php"
values = {
'fmt' = 'xml'
'zn' = '1500042'
}
params = par.urlencode(values)
url = API + "?" + params
This time I wrote an article for the first time using various notations, but since it takes a while and it is a waste of time, I will write it concisely as long as it stays in the learning record from tomorrow onwards.
Recommended Posts