Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从预订中仅返回酒店描述?_Python_Python 3.x_Scrapy - Fatal编程技术网

Python 如何从预订中仅返回酒店描述?

Python 如何从预订中仅返回酒店描述?,python,python-3.x,scrapy,Python,Python 3.x,Scrapy,如何从booking.com仅打印特定酒店的描述 例: 我使用此代码,但不返回任何代码 import requests from scrapy.selector import Selector url = 'https://www.booking.com/hotel/eg/mediterranean-azur.html?' response2 = requests.get(url) if response2.ok is True: selector = Selector(text

如何从booking.com仅打印特定酒店的描述

例:

我使用此代码,但不返回任何代码

import requests
from scrapy.selector import Selector

url = 'https://www.booking.com/hotel/eg/mediterranean-azur.html?'

response2 = requests.get(url)

if response2.ok is True:
    selector = Selector(text=response2.content)
    print(selector.xpath("//div[@class='hp__hotel-name']").get())
有什么帮助吗?

试试这个:

import requests
from bs4 import BeautifulSoup

url = "https://www.booking.com/hotel/eg/mediterranean-azur.uk.html?"

r = requests.get(url)
soup = BeautifulSoup(r.text, "lxml")
answ = soup.find("div", {"id":"property_description_content"}).text

谢谢你的回复。