以下是一个简单的爬虫示例,以爬取豆瓣电影排行榜为例:

import requests
from bs4 import BeautifulSoup

url = 'https://movie.douban.com/chart'
response = requests.get(url)

soup = BeautifulSoup(response.text, 'html.parser')
movies = soup.select('.pl2 a')

for movie in movies:
    title = movie.get_text().strip()
    url = movie['href']
    print(title, url)

这个爬虫使用requests库发送请求,然后使用BeautifulSoup库解析HTML页面,提取出电影的标题和URL,并打印出来。

你可以根据需要修改爬虫代码,以爬取你想要的网站和关键信息。但请注意,爬虫有可能会侵犯网站的利益或者违反法律法规,请谨慎使用。

使用python写一个可以爬取指定网站内关键信息的爬虫

原文地址: https://www.cveoy.top/t/topic/bb9b 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录