获取代理Ip
防止自己的Ip被封禁,最好用一下代理IP
代理IP网站可以检测一下是否能用,从中随机获取
import requests
from bs4 import BeautifulSoup
import random
import traceback
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 getHTML(url):
try:
r = requests.get(url,headers = headers,timeout = 30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
print</