diff --git a/060326-2509165004.py b/060326-2509165004.py new file mode 100644 index 0000000..679600a --- /dev/null +++ b/060326-2509165004.py @@ -0,0 +1,24 @@ +import requests +from bs4 import BeautifulSoup +import time + + +headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'} + +for i in range(5): + url = f'https://picsum.photos/' + response = requests.get(url, headers=headers,timeout=10) + response.encoding = 'utf-8' + soup = BeautifulSoup(response.text, 'html.parser') + +img_tag = soup.select_one('img.resize') +# print(img_tag) +if img_tag: + img_src = img_tag.get('src') + print(f"第{i+1}张图片地址:{img_src}") + + img_response = requests.get(img_src, timeout=10) + + with open('image_{i+1}.jpg', 'wb') as f: + f.write(img_response.content) + print(f"第{i+1}张图片保存成功!") \ No newline at end of file diff --git a/260324-2509165004.py b/260324-2509165004.py deleted file mode 100644 index d35a526..0000000 --- a/260324-2509165004.py +++ /dev/null @@ -1,21 +0,0 @@ -import requests -from bs4 import BeautifulSoup - -headers = { - 'User-Agent':'Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,like Gecko)Chrome/120.0.0.0 Safari/537.36', -} - -url = 'https://movie.douban.com/top250?start=0&filter=' - -response = requests.get(url,headers=headers,timeout=10) -response.encoding = 'utf-8' -soup = BeautifulSoup(response.text,'html.paser') -movies = [] -for a in soup.find_all('a'): - herf = a.get('href','') - if '/subject' in href: - title = a.get_text(strip=True) - print(title) - movies.append(title) -print('------------') -print(movies) \ No newline at end of file diff --git a/lxj.py b/lxj.py deleted file mode 100644 index 12c2dad..0000000 --- a/lxj.py +++ /dev/null @@ -1,8 +0,0 @@ -import requests -url = 'http://example.com' -params = {'key':'value'} -response = requests.get(url, params=params) -if response.status_code == 200: - print("请求成功,获取到HTML内容") -else: - print(f"请求失败,状态码:{response.status_code}") \ No newline at end of file diff --git a/lxj01.py b/lxj01.py deleted file mode 100644 index af96770..0000000 --- a/lxj01.py +++ /dev/null @@ -1,13 +0,0 @@ -from bs4 import BeautifulSoup -import requests -response = requests.get('https://example.com') -html_content = response.text -soup = BeautifulSoup(html_content,'lxml') -title = soup.find('title').string -print("页面标题:",title) -links = soup.find_all('a') -for link in links: - print("链接地址:",link.get('href')) -div_elements = soup.select('div.class_name') -for div in div_elements: - print("div内容:",div.text) \ No newline at end of file