本文整理匯總了Python中wpull.protocol.http.request.Response.fields["content-type"]方法的典型用法代碼示例。如果您正苦於以下問題:Python Response.fields["content-type"]方法的具體用法?Python Response.fields["content-type"]怎麽用?Python Response.fields["content-type"]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wpull.protocol.http.request.Response
的用法示例。
在下文中一共展示了Response.fields["content-type"]方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_html_serious_bad_encoding
# 需要導入模塊: from wpull.protocol.http.request import Response [as 別名]
# 或者: from wpull.protocol.http.request.Response import fields["content-type"] [as 別名]
def test_html_serious_bad_encoding(self):
element_walker = ElementWalker(css_scraper=CSSScraper(), javascript_scraper=JavaScriptScraper())
scraper = HTMLScraper(self.get_html_parser(), element_walker, encoding_override="utf8")
request = Request("http://example.com/")
response = Response(200, "")
response.body = Body()
response.fields["content-type"] = "text/html; charset=utf8"
with wpull.util.reset_file_offset(response.body):
html_file_path = os.path.join(ROOT_PATH, "testing", "samples", "xkcd_1_evil.html")
with open(html_file_path, "rb") as in_file:
shutil.copyfileobj(in_file, response.body)
scrape_info = scraper.scrape(request, response)
self.assertTrue(scrape_info)
示例2: test_html_encoding_lxml_name_mismatch
# 需要導入模塊: from wpull.protocol.http.request import Response [as 別名]
# 或者: from wpull.protocol.http.request.Response import fields["content-type"] [as 別名]
def test_html_encoding_lxml_name_mismatch(self):
"""It should accept encoding names with underscore."""
element_walker = ElementWalker(css_scraper=CSSScraper(), javascript_scraper=JavaScriptScraper())
scraper = HTMLScraper(self.get_html_parser(), element_walker)
request = Request("http://example.com/")
response = Response(200, "")
response.body = Body()
response.fields["content-type"] = "text/html; charset=EUC_KR"
with wpull.util.reset_file_offset(response.body):
response.body.write("힖".encode("euc_kr"))
scrape_info = scraper.scrape(request, response)
self.assertTrue(scrape_info)
self.assertEqual("euc_kr", scrape_info["encoding"])
示例3: test_html_garbage
# 需要導入模塊: from wpull.protocol.http.request import Response [as 別名]
# 或者: from wpull.protocol.http.request.Response import fields["content-type"] [as 別名]
def test_html_garbage(self):
element_walker = ElementWalker(css_scraper=CSSScraper(), javascript_scraper=JavaScriptScraper())
scraper = HTMLScraper(self.get_html_parser(), element_walker)
request = Request("http://example.com/")
response = Response(200, "")
response.body = Body()
response.fields["content-type"] = "text/html"
with wpull.util.reset_file_offset(response.body):
response.body.write(
b"\x01\x00\x01\x00l~Z\xff\x0f`y\x80\x00p<\x7f"
b"\xffndo\xff\xff-\x83{d\xec</\xfe\x80\x00\xb4Bo"
b"\x7f\xff\xff\xffV\xc1\xff\x7f\xff7"
)
scrape_info = scraper.scrape(request, response)
self.assertTrue(scrape_info)
示例4: test_rss_as_html
# 需要導入模塊: from wpull.protocol.http.request import Response [as 別名]
# 或者: from wpull.protocol.http.request.Response import fields["content-type"] [as 別名]
def test_rss_as_html(self):
element_walker = ElementWalker(css_scraper=CSSScraper(), javascript_scraper=JavaScriptScraper())
scraper = HTMLScraper(self.get_html_parser(), element_walker)
request = Request("http://example.com/")
response = Response(200, "")
response.body = Body()
response.fields["content-type"] = "application/rss+xml"
with wpull.util.reset_file_offset(response.body):
html_file_path = os.path.join(ROOT_PATH, "testing", "samples", "rss.xml")
with open(html_file_path, "rb") as in_file:
shutil.copyfileobj(in_file, response.body)
scrape_result = scraper.scrape(request, response)
self.assertTrue(scrape_result)
inline_urls = scrape_result.inline_links
linked_urls = scrape_result.linked_links
self.assertFalse(inline_urls)
self.assertEqual({"http://www.someexamplerssdomain.com/main.html", "http://www.wikipedia.org/"}, linked_urls)
示例5: test_html_krokozyabry
# 需要導入模塊: from wpull.protocol.http.request import Response [as 別名]
# 或者: from wpull.protocol.http.request.Response import fields["content-type"] [as 別名]
def test_html_krokozyabry(self):
element_walker = ElementWalker(css_scraper=CSSScraper(), javascript_scraper=JavaScriptScraper())
scraper = HTMLScraper(self.get_html_parser(), element_walker)
request = Request("http://example.com/")
response = Response(200, "")
response.body = Body()
response.fields["content-type"] = "text/html; charset=KOI8-R"
with wpull.util.reset_file_offset(response.body):
html_file_path = os.path.join(ROOT_PATH, "testing", "samples", "krokozyabry.html")
with open(html_file_path, "rb") as in_file:
shutil.copyfileobj(in_file, response.body)
scrape_result = scraper.scrape(request, response)
inline_urls = scrape_result.inline_links
linked_urls = scrape_result.linked_links
self.assertEqual("koi8-r", scrape_result.encoding)
self.assertEqual(set(), inline_urls)
self.assertEqual({"http://example.com/Кракозябры"}, linked_urls)