赞
踩
此案例是运用bs4库find方法对相关内容进行抓取。
-*- coding: utf-8 -*- import requests import csv from bs4 import BeautifulSoup as bs #获取网页信息 def request_dandan(url): try: #用户代理 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'} r = requests.get(url,headers=headers) if r.status_code == 200: return r.text except requests.RequestException: return None #存放列名 def write_item_to_file(): csv_file = open('dangdang.csv', 'w', newline='', encoding="utf-8") writer = csv.writer(csv_file) writer.writerow([
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。