python爬取知乎的网站内容
#获取知乎的网站内容
import requests #数据请求模块 第三方模块 pip install requests
import re #正则表达式
#网页head头
heads = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36'
}
def get_response(html_url):
response = requests.get(url=html_url, headers=heads)
return response
url= 'https://zhuanlan.zhihu.com/p/435694901'
response_new = get_response(html_url=url)
print(response_new.text)
#<p data-pid="R1eByHKC">100. 如果你拥有一种超能力,你会用它去做什么</p>
html_data = re.findall('<p data-pid="\w+">(.*?)</p>', response_new.text)
print(html_data)
for url in html_data:
print(url)
做一个决定,并不难,难的是付诸行动,并且坚持到底。

浙公网安备 33010602011771号