爬虫python我爱卡
时间: 2023-12-13 08:34:07 浏览: 29
以下是使用BeautifulSoup库和pyquery库进行爬虫的Python代码,可以爬取我爱卡网站的相关信息:
使用BeautifulSoup库进行爬虫:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.52kak.com/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
news_list = soup.find_all('div', class_='news-item')
for news in news_list:
title = news.find('a').text.strip()
link = news.find('a')['href']
print(title)
print(link)
print('---')
```
使用pyquery库进行爬虫:
```python
import urllib.request
from pyquery import PyQuery as pq
url = 'https://www.52kak.com/'
response = urllib.request.urlopen(url)
html = response.read()
doc = pq(html)
news_list = doc('.news-item')
for news in news_list.items():
title = news.find('a').text()
link = news.find('a').attr('href')
print(title)
print(link)
print('---')
```