网页上查看汇率:
保存到本地效果:
代码实现如下:
import requests from bs4 import BeautifulSoup url='http://fx.xxx/' #commentthe actual URL for acticle publish res=requests.get(url) content=res.text soup=BeautifulSoup(content,'html.parser') all_ccy=soup.find_all(id='realRateInfo') ccy_table=[] for ccy in all_ccy: ccy_name=ccy.find('table') for ccy1 in ccy_name: ccy2=ccy1.text ccy3=ccy2.replace(' ','') #remove whitespace ccy_for_table=ccy3.strip().replace('\r\n\n\r\n',',') #remove empty lines ccy_for_table2=ccy_for_table.strip().replace('\r\n\n\n查