Home > other >  Baidu dynamic web pages grab you want pictures
Baidu dynamic web pages grab you want pictures

Time:11-27

The import requests
The import re
The from bs4 import BeautifulSoup
The import OS
The import time


Key=input (" please enter your query: ") # you want to search for information
Mz=key
OS. The mkdir (' C: \ \ Users \ \ Lenovo \ \ Desktop \ \ '+ mz) # on your Desktop to create a search keywords you input folder
For page in range (winter 0120) : # 30 incremental steps dynamic web pages every step, I set up 30=120 divided by four dynamic pages, each page draw 30 total is 120 or so, you can also set a few more page number is 30 multiples,
Url="https://image.baidu.com/search/index? Tn=baiduimage& Ipn=utf-8 & amp; Sid=& amp; The word='+ (key) +' & amp; Pn={} 'format (STR (page))
Headers={' the user-agent ':' Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 '}
Data=https://bbs.csdn.net/topics/requests.get (url, headers=headers)
Text=requests. Get (url). The text
Print (url. The format (page))
Image=re. The.findall (' "hoverURL" : "(. *?) "', text) # image name
For I in image:
Time. Sleep (0.2) # crawl time interval
Imgname=i. plit ('/') [1] # image retrieval
Tp=requests. Get (I, headers=headers) # image parsing
With the open (' C: \ \ Users \ \ Lenovo \ \ Desktop \ \ '+ + imgname mz +' \ \ ', 'wb) as file: # save local folder location and binary
File. The write (tp) content) # image after binary parsing save
Print (imgname)

  • Related