爬取某网站的潮汐数据
import re,os
import requests
import datetime
import random
import time
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}
def post_html(url,date):
files = {
"date":(None,date)}
html = requests.post(url,files = files).text
print(html)
return html
def get_html(url):
html = requests.get(url, headers=headers).text
return html
def get_chaoshi(html):
resa = r'<tr>.*?<td>潮时</td>(.*?)</tr>'
contenta = re.compile(resa, re.DOTALL).findall(html)
resb = '<td>(.*?)</td>'
contentb = re.compile(resb, re.DOTALL).findall(contenta[0])
return contentb
def get_chaogao(html):
resa = r'<tr>.*?<td>潮高(峰值)</td>(.*?)</tr>'
resa = '<td>潮高.*?</td>(.*?)</tr>'
contenta = re.compile(resa, re.DOTALL).findall(html)
resb = '<td>(.*?)cm</td>'
contentb = re.compile