在Python中,爬虫可以通过以下几种方法查看正在请求的URL信息:
1. 使用`requests`库的`url`属性:
import requests
response = requests.get('https://example.com')
print(response.url) 打印请求的URL
2. 使用`urllib`库的`geturl()`方法:
from urllib.request import urlopen
response = urlopen('https://example.com')
print(response.geturl()) 打印请求的URL
3. 使用`BeautifulSoup`库的`current_url`属性:
from bs4 import BeautifulSoup
html = """
Example