from scrapy.http import TextResponse import requests response = requests.get("https://www.example.com") text_response = TextResponse(url=response.url, body=response.text, encoding='utf-8') html_content = text_response.xpath('//html').get() print(html_content)
from scrapy.http import TextResponse import requests response = requests.get("https://www.example.com") text_response = TextResponse(url=response.url, body=response.text, encoding='utf-8') cookie_info = text_response.headers.getlist('Set-Cookie') print(cookie_info)In this example, we first make a GET request to a website using the requests library. We then create a scrapy.http TextResponse object with the URL, HTML content, and encoding of the website. We use the headers method to get the cookie information and print it. Overall, Scrapy is an incredibly useful and powerful library for web scraping and the scrapy.http TextResponse class is essential for extracting data from web pages.