Python crawling reptiles entry --requests single image / video

Environment:
python3 +
IDE: In this crawling in, no ide, only terminal can actually, where I use pycharm
ready to
prepare :: installation requests library, through the terminal pip install, here I was directly in pycharm installed lightbulb Tip direct the installation is complete, it is very simple.
Crawling pictures
when you're ready to consider this operation is relatively simple, we have direct command-line completion of ok in the terminal
import requests package
import requests
the relationship between the location of the establishment to address crawling and pictures on your computer where you want to store

>>>import requests
>>> url="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1570106627669&d
i=201664c4f778c834cfbc9a7e9d0afe69&imgtype=0&src=http%3A%2F%2Fpic44.nipic.com%2F20140727%2F1
8179070_152408117000_2.jpg"
>>> path="D:/picture/pythonpicture.jpg"

The pictures can be found here addresses a picture from right-click to copy the link for the evening.
Get address

>>> r=requests.get(url)

Check whether the acquired address

>>> r.status_code

200 can see the output
picture content written on the path

with open(path, 'wb') as f:
    f.write(r.content)

We can see already have set up their own storage location of the picture
finally close to

f.close()

As with pictures on acquiring video, but the video picture address into the address (for example, the end of the mp4 format can be), note the file path name format should change it

Published 37 original articles · won praise 1511 · Views 160,000 +

Guess you like

Origin blog.csdn.net/weixin_43943977/article/details/102009719