Response 中To header中的tag必须存在(除了100)

sec8.2.6.2 Headers and Tags of RFC3261

 

   If a request contained a To tag in the request, the To header field
   in the response MUST equal that of the request. 

  

   However, if the To 

   header field in the request did not contain a tag, the URI in the To
   header field in the response MUST equal the URI in the To header
   field; additionally, the UAS MUST add a tag to the To header field in
   the response (with the exception of the 100 (Trying) response, in
   which a tag MAY be present).  This serves to identify the UAS that is
   responding, possibly resulting in a component of a dialog ID.  The
   same tag MUST be used for all responses to that request, both final
   and provisional (again excepting the 100 (Trying)).  Procedures for
   the generation of tags are defined in Section 19.3.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是每一行代码的解释: ``` -- coding: utf-8 -- ``` 这一行表示文件编码格式为 UTF-8。 ``` from bs4 import BeautifulSoup from items import TravelsDetailItem from scrapy_redis.spiders import RedisCrawlSpider ``` 这三行分别导入了 BeautifulSoup、TravelsDetailItem 和 RedisCrawlSpider 三个类。 ``` class TuniudetailSpider(RedisCrawlSpider): ``` 定义了一个名为 TuniudetailSpider 的类,继承了 RedisCrawlSpider 类。 ``` name = "detail_urls" ``` 定义了爬虫的名称为 detail_urls。 ``` allowed_domains = ["trips.tuniu.com"] ``` 定义了允许爬取的域名。 ``` redis_key = "tuniu:detail_urls" ``` 定义了 redis_key,使用 Redis 存储爬取的 URL。 ``` def parse(self, response): ``` 定义了一个名为 parse 的方法,用于解析爬取到的响应。 ``` soup = BeautifulSoup(response.text) ``` 使用 BeautifulSoup 库对响应的 HTML 内容进行解析。 ``` tag_list_div = soup.find('div', {'class': 'tag-list clearfix'}) tag_list = tag_list_div.find_all('div') tags = [] for i in tag_list: tags.append(i.text) ``` 从 HTML 内容提取标签信息,将其存储在列表 tags 。 ``` try: destination = soup.find('div', {'class': 'poi-container-header'}).p.text destination = destination.strip() price = soup.find('div', {'class': 'gallery-text-info'}).p.span.text except Exception as e: destination="" price="" ``` 从 HTML 内容提取目的地和价格信息,如果提取失败则将值设为空字符串。 ``` item = TravelsDetailItem() item["taglist"] = ",".join(tags) item["destination"] = destination item["price"] = price item["id"] = response.url.split("/")[-1] ``` 创建一个 TravelsDetailItem 对象,并将提取到的信息存储到该对象。 ``` return item ``` 返回 TravelsDetailItem 对象,供后续处理。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值