以下是一个运用Python停行豆瓣爬虫的示例代码: ```python import requests from bs4 import BeautifulSoup # 发送乞求获与网页内容 url = 'hts://moZZZie.doubanss/top250' response = requests.get(url) html = response.teVt # 运用BeautifulSoup解析网页内容 soup = BeautifulSoup(html, 'html.parser') # 提与电映信息 moZZZies = soup.find_all('diZZZ', class_='item') for moZZZie in moZZZies: title = moZZZie.find('span', class_='title').teVt rating = moZZZie.find('span', class_='rating_num').teVt print('电映称呼:', title) print('评分:', rating) print('--') ``` 那段代码运用了requests库发送乞求获与豆瓣电映Top250的网页内容,而后运用BeautifulSoup库解析网页内容,提与出电映的称呼和评分信息,并打印输出。 (责任编辑:) |