Skip to main content

Posts

Showing posts with the label python

Python crawlers to crawl pure girl pictures

Before running the code, you need to install BeautifulSoup, requests, os library. From bs4 import BeautifulSoup Import requests Import time Import os Def get_html(url):     Try:         Response=requests.get(url)         Response.encoding='gb2312'         If response.status_code==200:             Print('Successfully connected! URL is '+url)             Return response.text     Except requests.RequestException:        Return None Def get_url_and_name(url):     "The passed argument is the main page link, the return value is a list with 2 elements, element 1 is the map package link, and element 2 is the map package name."     Html=get_html(url)     Soup=BeautifulSoup(html,'lxml')     Name=[]     Url_1=[]     List2=soup.find_all(class_='t')     Sign=1     For item in list2:         If(sign!=1 and sign!=42):             Url_temp=item.find('a').get('href')             Name_temp=

How to download pictures from Baidu Image with python

With below script, you can download specific pictures to a folder. # coding: utf-8 import requests import os def getManyPages(keyword,pages): params=[] for i in range(30,30*pages+30,30): params.append({ 'tn': 'resultjson_com', 'ipn': 'rj', 'ct': 201326592, 'is': '', 'fp': 'result', 'queryWord': keyword, 'cl': 2, 'lm': -1, 'ie': 'utf-8', 'oe': 'utf-8', 'adpicid': '', 'st': -1, 'z': '', 'ic': 0, 'word': keyword, 's': '',