帮我用python语言写一段可抓取PHP网页的爬虫工具的代码
时间: 2023-03-15 20:22:15 浏览: 139
Python网页爬虫代码
这是一段使用Python编写的爬虫工具代码,用来抓取PHP网页:import requests
from bs4 import BeautifulSoupurl = '要爬取的网页地址'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'}# 获取网页
response = requests.get(url,headers=headers)# 使用BeautifulSoup解析网页
soup = BeautifulSoup(response.text, 'html.parser')# 找出需要的内容
content = soup.find_all('div', attrs={'class':'content'})# 输出
for item in content:
print(item.get_text())
阅读全文