Python 如何从预订中仅返回酒店描述?
如何从booking.com仅打印特定酒店的描述 例: 我使用此代码,但不返回任何代码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
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
谢谢你的回复。