我试图通过从https://goldprice.org/抓取信息来获得最新的黄金与美元的比率。如何在Python中使用handle
或urllib
来执行此操作?
requests
答案 0 :(得分:1)
利用请求:
CalculateEarliestStartDate
或者如果您使用的是urllib
import requests
from bs4 import BeautifulSoup
header = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36","X-Requested-With": "XMLHttpRequest"}
url = 'https://goldprice.org/'
r = requests.get(url, headers = header)
soup = BeautifulSoup(r.text, 'html.parser')