Python 漂亮的汤在第一个div标签后不能刮

Python 漂亮的汤在第一个div标签后不能刮,python,web-scraping,beautifulsoup,web-crawler,Python,Web Scraping,Beautifulsoup,Web Crawler,请看下面。我想勉强拼凑一下餐厅的名字 大眼仔 请参阅下面的图片,了解本网站上的HTML 有人能告诉我怎么用漂亮的汤或其他垃圾包装在Python上刮那个餐馆的名字Popeyes吗 提前谢谢 下面是我用来抓取数据的代码,但是,它停在了,我不能再进一步了。 ' 从bs4导入BeautifulSoup作为soup HTML数据结构 从urllib.request导入urlopen作为uReq Web客户端 # URl to web scrape from. # in this example we we

请看下面。我想勉强拼凑一下餐厅的名字

大眼仔 请参阅下面的图片,了解本网站上的HTML

有人能告诉我怎么用漂亮的汤或其他垃圾包装在Python上刮那个餐馆的名字Popeyes吗

提前谢谢

下面是我用来抓取数据的代码,但是,它停在了,我不能再进一步了。 ' 从bs4导入BeautifulSoup作为soup HTML数据结构 从urllib.request导入urlopen作为uReq Web客户端

# URl to web scrape from.
# in this example we web scrape graphics cards from Newegg.com
page_url = "https://www.doordash.com/store/popeyes-toronto-254846/en-CA"

# opens the connection and downloads html page from url
uClient = uReq(page_url)

# parses html into a soup data structure to traverse html
# as if it were a json data type.
page_soup = soup(uClient.read(), "html.parser")
uClient.close()

page_soup.div'''

你可以试试这个,我可能会在类名上出错:

import urllib.request
import bs4 as bs
from bs4 import BeautifulSoup

url_1 = 'https://www.doordash.com/store/popeyes-toronto-254846/en-CA'
sauce_1  = urllib.request.urlopen(url_1).read()
soup_1 = bs.BeautifulSoup(sauce_1, 'lxml')     

for x in (soup_1.find_all('h1', class_ = 'sc-AnqlK keKZVr sc-jFpLkX bsGprJ')):
   print(x)

让我知道这是否有帮助

您可以通过指定'div'类来获得名称

from bs4 import BeautifulSoup
import requests

headers = {
     "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
     }

response = requests.get(url, headers = headers)
soup = BeautifulSoup(response.content, 'html.parser')
soup.encode('utf-8')

title = soup.find(class_ = 'sc-AnqlK keKZVr sc-jFpLkX bsGprJ').get_text()

print(title)

我不知道类名写得是否正确,但您可以复制并粘贴它。

请以文本而不是图像的形式提供代码。您好,M Z,谢谢您的回复。当我复制HTMl时,它看起来很长,所以我认为直接向您发送链接可能更有效。下面是我正在努力浏览的链接,我现在只想知道餐厅的名称,最终还有餐厅的等级和类型。因此,这不是编码服务。您必须首先尝试,如果遇到问题,请发布代码并告诉我们问题所在。您好,Matteo,谢谢您回答我的问题。但是,我不确定发生了什么,代码似乎没有输出。我在做一些研究,我想这可能是网站上的某种动态内容。Selenium可能能够很明显地将其刮去,但我对web刮去还很陌生,所以这有点太高级了。