在Mac上保存网页上的图片

1.鼠标右键“将页面存储为”=>保存为一个"xxx.webarchive"文件;

2.将.webarchive文件转为html的文件夹,使用到终端指令工具,确保已安装textutil,未安装可以使用brew安装;

brew install textutil

textutil -convert html xxx.webarchive

3.最终得到包含该网页所有图片及html文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在这里,我给出了一个示例程序,它使用 Python 的 requests 库和 BeautifulSoup 库来爬取微博信息。它将爬取的信息保存在一个字典中,然后使用 pandas 库将字典转换为 DataFrame,最后使用 pandas 库的 to_excel 方法将 DataFrame 保存到 Excel 中。 请注意,此程序仅作为示例提供,并且需要您自行替换相应的 URL 和请求头信息。 ```python import requests from bs4 import BeautifulSoup import pandas as pd # 定义一个函数来爬取微博信息 def crawl_weibo(keyword, page): # 构造请求头信息 headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36', 'Cookie': 'YOUR_COOKIE' # 替换为你的 Cookie } # 构造 URL url = f'https://s.weibo.com/weibo?q={keyword}&page={page}' # 发起请求 response = requests.get(url, headers=headers) # 使用 BeautifulSoup 解析 HTML 页面 soup = BeautifulSoup(response.text, 'html.parser') # 找到所有的微博 div 元素 weibo_divs = soup.find_all('div', class_='card-wrap') # 定义一个列表来保存爬取的信息 weibo_list = [] # 遍历微博 div 元素 for weibo_div in weibo_divs: # 找到 div 中的所有 p 元素 ps = weibo_div.find_all('p') # 第一个 p 元素是发布时间,第二个 p 元素是内容 created_at = ps[0].text content = ps[1]. ### 回答2: 使用Python爬取关于“小牛”的微博信息,并保存在Excel中,可以通过以下步骤来实现: 1. 导入所需模块:使用`requests`模块发送HTTP请求,使用`bs4`模块解析HTML页面,使用`openpyxl`模块创建并操作Excel文件。 ```python import requests from bs4 import BeautifulSoup from openpyxl import Workbook ``` 2. 创建一个工作簿,并添加一个工作表: ```python wb = Workbook() ws = wb.active ws.append(['微博内容', '点赞数', '转发数', '评论数', '图片链接']) ``` 3. 发送HTTP请求获取微博页面,并使用BeautifulSoup解析页面: ```python url = 'https://weibo.com/?category=10011' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36' } response = requests.get(url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') ``` 4. 使用BeautifulSoup的选择器定位微博信息,并获取需要的内容: ```python weibo_list = soup.select('.WB_detail .WB_feed_detail .WB_detail .WB_text') for weibo in weibo_list[:50]: # 只获取前50条微博 content = weibo.get_text(strip=True) # 微博内容 likes = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos em:nth-child(2)').get_text(strip=True) # 点赞数 forwards = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos em:nth-child(4)').get_text(strip=True) # 转发数 comments = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos em:nth-child(6)').get_text(strip=True) # 评论数 image = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos img') # 图片链接 if image: image_link = image['src'] else: image_link = '' ws.append([content, likes, forwards, comments, image_link]) # 将微博信息添加到工作表中 ``` 5. 保存Excel文件: ```python wb.save('weibo.xlsx') ``` 完整代码如下所示: ```python import requests from bs4 import BeautifulSoup from openpyxl import Workbook wb = Workbook() ws = wb.active ws.append(['微博内容', '点赞数', '转发数', '评论数', '图片链接']) url = 'https://weibo.com/?category=10011' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36' } response = requests.get(url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') weibo_list = soup.select('.WB_detail .WB_feed_detail .WB_detail .WB_text') for weibo in weibo_list[:50]: content = weibo.get_text(strip=True) likes = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos em:nth-child(2)').get_text(strip=True) forwards = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos em:nth-child(4)').get_text(strip=True) comments = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos em:nth-child(6)').get_text(strip=True) image = weibo.find_previous_sibling(class_='WB_handle').select_one('.WB_handle .WB_handle .pos .pos img') if image: image_link = image['src'] else: image_link = '' ws.append([content, likes, forwards, comments, image_link]) wb.save('weibo.xlsx') ``` 运行以上代码后,就能在当前目录下生成一个名为`weibo.xlsx`的Excel文件,包含关于“小牛”的50条微博信息,包括微博内容、点赞数、转发数、评论数和图片链接。 ### 回答3: 要用Python语言编写程序爬取关于“小牛”的五十条微博信息,可以借助第三方库BeautifulSoup和openpyxl来实现。下面给出一个简单的实现思路: 1. 导入必要的库,包括requests、BeautifulSoup和openpyxl。 2. 提供微博用户的主页链接,利用requests库向该链接发送请求,获取微博主页的HTML源代码。 3. 使用BeautifulSoup解析HTML源代码,提取出微博信息的相关标签。可以通过查看微博主页的HTML结构,找到点赞数、转发数、评论数等信息所对应的标签。 4. 根据需求,可以使用正则表达式或BeautifulSoup提供的其他方法进一步筛选出所需的微博信息,并保存在一个列表中。 5. 根据微博的图片链接,可以使用requests库下载图片保存到本地。 6. 使用openpyxl库创建一个新的Excel文件,并创建一个工作表。 7. 将保存的微博信息按照要求写入Excel文件的对应单元格中。 8. 保存Excel文件。 下面是一个简单的示例代码: ```python import requests from bs4 import BeautifulSoup from openpyxl import Workbook url = 'https://weibo.com/u/xxxxxxxxx' # 将xxxxxxxxx替换为对应微博用户的ID response = requests.get(url) html = response.text soup = BeautifulSoup(html, 'html.parser') weibo_list = soup.find_all('div', class_='weibo-item')[:50] # 获取前50条微博 wb = Workbook() ws = wb.active for i, weibo in enumerate(weibo_list): like_count = weibo.find('span', class_='like').text repost_count = weibo.find('span', class_='forward').text comment_count = weibo.find('span', class_='comment').text # 提取点赞数、转发数和评论数等信息,可以根据实际情况进一步筛选 # 下载微博图片 image_url = weibo.find('img')['src'] image_data = requests.get(image_url).content image_path = f'image_{i+1}.jpg' with open(image_path, 'wb') as f: f.write(image_data) ws.cell(row=i+1, column=1, value=like_count) ws.cell(row=i+1, column=2, value=repost_count) ws.cell(row=i+1, column=3, value=comment_count) ws.cell(row=i+1, column=4, value=image_path) wb.save('weibo.xlsx') ``` 这段代码只是一个简单的示例,具体实现还需要根据微博页面的结构以及自己的需求进行适当调整和完善。还要注意爬取网页信息时需要遵守相关法律法规,并尊重网站的隐私政策和用户协议。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值