a标签属性target =“_ blank“是否需要加下划线?

正确答案是:必须要加下划线!!!

target="blank"在功能上看上去和target="_blank"一样,都是跳转到一个新页面。并且在Chrome、Firefox、Safari等浏览器也能正常跳转,兼容性没有问题。

{/* value的值从后端接口获取 */}
<a href={ `${value}` } target = "blank" >
  { value }
< /a>
<a href={ `${value}` } target = "_blank" >
  { value }
< /a>

当我们使用第一个写法(不加_),连续多次点击a标签后,我们会发现总是跳转到第一次打开的新页面,即同一个页面,

第二个写法(加_),多次点击会新增多个新页面,这才是我们需要的功能!

官方a标签的target属性都是加下划线的,链接如下:

https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/a

补充:那为什么target="blank"这个错误写法依然能跳转一个新页面呢?

由于不是关键词'_blank',所以默认为新页面的名称为blank。

import requests from bs4 import BeautifulSoup import re import os import json from datetime import datetime # 目标URL url = "https://listing.szse.cn/projectdynamic/ipo/detail/index.html?id=1003423" # 创建存储目录 if not os.path.exists('./ipo_documents'): os.makedirs('./ipo_documents') # 请求头 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', 'Connection': 'keep-alive', 'Referer': 'https://listing.szse.cn/disclosure/ipo/index.html' } def extract_document_links(html_content): """从HTML内容中提取文档链接""" soup = BeautifulSoup(html_content, 'html.parser') # 查找所有包含文档的表格行 rows = soup.select('tr') documents = [] current_category = None for row in rows: # 检查是否是类别行(包含<th>标签) if row.find('th'): current_category = row.get_text(strip=True) continue # 检查是否是文档行 if row.find('td'): tds = row.find_all('td') # 确保有足够的列 if len(tds) > 1: doc_name = tds[0].get_text(strip=True) # 处理日期和链接列 date_links = [] for td in tds[1:]: # 查找所有链接 for link in td.find_all('a', href=True): date_text = link.get_text(strip=True) file_url = link['href'] # 清理URL中的空格和特殊字符 file_url = re.sub(r'\s+', '', file_url) file_url = file_url.replace('”', '').replace('"', '') # 跳过无效URL if file_url.startswith('http'): date_links.append({ 'date': date_text, 'url': file_url }) # 添到文档列表 if doc_name and date_links: for dl in date_links: documents.append({ 'category': current_category, 'document_name': doc_name, 'publish_date': dl['date'], 'file_url': dl['url'] }) return documents def main(): print(f"开始爬取IPO项目详情页: {url}") try: # 发送HTTP请求 response = requests.get(url, headers=headers) response.raise_for_status() # 检查请求是否成功 # 解析文档链接 documents = extract_document_links(response.text) if documents: # 创建结果文件名 timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") output_file = f"./ipo_documents/project_1003423_{timestamp}.json" # 保存结果到JSON文件 with open(output_file, 'w', encoding='utf-8') as f: json.dump(documents, f, ensure_ascii=False, indent=2) print(f"\n爬取完成! 共找到 {len(documents)} 个文档链接") print(f"结果已保存到: {output_file}") # 打印前3个结果示例 print("\n文档链接示例:") for i, doc in enumerate(documents[:3]): print(f"{i + 1}. {doc['category']} - {doc['document_name']}") print(f" 发布日期: {doc['publish_date']}") print(f" 文件URL: {doc['file_url']}\n") else: print("未找到任何文档链接") except requests.exceptions.RequestException as e: print(f"请求失败: {str(e)}") except Exception as e: print(f"发生错误: {str(e)}") if __name__ == '__main__': main() 修改代码,帮我提取出下列html中的pdf链接到代码中,让运行后的代码下载出pdf文件进行存放。<td>招股说明书</td) ▼<td class="text-center target="_blank' ”href="httns://reDortdocs.static.sZse.cn/UpFi1es/rasinfodisc1/202306/RAS 202306 EFF55B536A0445029A7FC26A9AFDC151.Ddf" style="display:block;">2023-06-27</a <a target="_b1ank"href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202312/RAS 202312 31160583E7E90B12654185BD6F9CCCA47976D6.pdf" href= style="display:block;">2023-12-31</a <a target= "_blank href="https://reDortdocs.static.szse.cn/UpFi1es/rasinfodisc1/202403/RAS 202403 1518253651462FDD5744BFBF999BDCA530BBD1.Ddf" style="display:block;">2024-03-15</a <a target="_b1ank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202407/RAS 202407 2521201348F597A7C0408EAA0147A41BBA30E8.pdf" sty1e="display:b1ock;">2024-07-25</a /a target= "blank' href="httDs://reDortdocs.statiC.SZse.Cn/UpFi1es/rasinf9disc1/202409/RAS 202409 111700A6910513E1C7459DBC9F23DA12258A8E.Ddf” style="display:block;">2024-09-11</a /2 target="blank" href= "https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202503/RAS_202503_2021351592FBC4C28B461CB055581BCF516C3E.pdf ”sty1e="disp1ay:b1ock;">2025-03-20</a </td ▼<td class="text-center atarget=”_b1ank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202506/RAS 202506 1021050A714A3ED75944E597BBAED9456B6037.pdf" style="display:block;">2025-06-10</a </td ▼<td class="text-center") target="_blank" href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202507/RAS 202507 041725E36EB4D843004F0997B334B64E5003BA. pdf” sty1e="disp1ay:b1ock;">2025-07-04</a </td </tr> (tr <td>发行保荐书</td> ▼<td class="text-center") target=”blank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202306/RAS 202306 58E303FEE6224DA2BC2F9E3E6AFA0AD7.pdf”style="display:block:">2023-06-27</a) <a target="_blank"href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202312/RAS 202312 311605D9B366F45DDF48309F197AA265B20214.pdf”style="display:block;">2023-12-31</a <a target=”_blank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202403/RAS 202403 151825E9082653339C4865B0AACF747572A8C6.pdf” sty1e="disp1ay:b1ock:">2024-03-15</a <a target="_blank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202407/RAS_202407 252120477EFCFD25BF4D50B92F00170E5260C0.pdf" style="disp1ay:b1ock;">2024-07-25</a /8 target="_blank" "href="https://reP0rtdocs.static.Szse.cn/UpFi1es/rasinfodisc1/202409/RAS 202409 1117006A832FC0F83C4E028E66B7FF1A096760.pdf" sty1e="display:block;">2024-09-11</a <a target="_b1ank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202503/RAS 202503 202135865CD83D4D6E49F1809648ACAAD8E5E7.pdf" target= style="display:block;">2025-03-20</a </td) ▼<td class="text-center" target=”_blank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202506/RAS 202506 102105190C786D6F404C0DA93711F9C5B62411.pdf”style="disp1ay:b1ock:">2025-06-10</a </td) ▼<td class="text-center" target="_b1ank”href="https://reportdocs.static.szse.cn/UpFiles/rasinfodisc1/202507/RAS_202507 041725EA0CD092A7754891A7BA76821E20494E.pdf”style="disp1ay:b1ock;">2025-07-04</a </td </tr) <trhttps://listing.szse.cn/projectdynamic/ipo/detail/index.html?id=1003423 ,帮我爬取网址中的披露文件的链接等相关信息,帮我写出具体的python代码。
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值