python - 如何获取soup代表的url?
问题描述
BeautifulSoup之后如何获取页面的url?
res = requests.get('http://www.example.com')
soup = BeautifulSoup(res.text, 'lxml')
如何http://www.example.com
从汤中获得?
解决方案
试试这个:
soup.url = 'http://www.example.com'
传递soup
给函数后,您可以调用soup.url
get http://www.example.com
。