我在Zomato网站上尝试网页抓取。 我只想对1家餐厅发表评论
import requests
from bs4 import BeautifulSoup
import re
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'}
r = requests.get('https://www.zomato.com/mumbai/joeys-pizza-malad-west/reviews',headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
#regex = re.compile('.*comment.*')
results = soup.find_all('p', {'class':'sc-1hez2tp-0 sc-eomEcv kOjze'})
reviews = [result.text for result in results]
我想从这个URLhttps://www.zomato.com/mumbai/joeys-pizza-malad-west/reviews中刮取所有用户的评论
将
headers
更改如下:此外,类名是动态加载的,并不断更改。相反,您可以做的是找到没有更改的类} 方法找到包含所需输出的前一个
sc-1hez2tp-0 fKvqMN
,然后使用^{p
输出:
相关问题 更多 >
编程相关推荐