import re
import os
import requests
import bs4
def open_url(url):
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"}
html = requests.get(url,headers = headers)
return html
def get_img(html):
file_name = 'image2.html'
with open(file_name,'w',encoding='utf-8') as file_obj:
file_obj.write(html.text)
soup = bs4.BeautifulSoup(html.text,"lxml")
content = soup.select("img.BDE_Image")
print(content)
'''
print("一共有")
print(len(imglist))
for each in imglist:
print(each)
print("yes!")
for each in imglist:
filename = each.split("/")[-1]
urllib.request.urlretrieve(each,filename,None)
'''
if __name__=='__main__':
url='https://tieba.baidu.com/p/6216578674'
get_img(open_url(url))
|