房产知识问答.
思路分析:
1.利用requests获取html文件
2.利用BeautifulSoup解析文件,获取问题和答案的字段
3.保存问答信息到本地文件
import requests
from bs4 import BeautifulSoup
import os
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}
def getHTMLtext(url):
try:
r = requests.get(url,headers = headers,timeout = 30)
r.raise_for_status()
r.encoding = r.apparent_encoding