python代码实现:爬取https://www.tsrcw.com/companyhome/post.aspx?comp=Z29zcGVscG93ZXI%3d&id=145629调用action的json数据方法
时间: 2023-06-12 14:05:25 浏览: 45
以下是使用Python爬取https://www.tsrcw.com/companyhome/post.aspx?comp=Z29zcGVscG93ZXI=的代码示例:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.tsrcw.com/companyhome/post.aspx?comp=Z29zcGVscG93ZXI='
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
posts = soup.find_all('div', class_='post-item')
for post in posts:
title = post.find('h3').text.strip()
date = post.find('span', class_='date').text.strip()
link = 'https://www.tsrcw.com' + post.find('a')['href']
print(f'{title} - {date}\n{link}\n')
```
该代码使用requests库获取网页内容,并使用BeautifulSoup库解析HTML。通过查找class为`post-item`的div标签,可以获取到每篇文章的标题、发布日期和链接。最后将这些信息打印出来。