【发布时间】:2021-09-15 03:23:34
【问题描述】:
由于某种原因,youtube 只给我他们的资源页面,而不是给我他们的视频链接 这就是我要找的。p>
代码:
import mechanize
import urllib
import urllib.parse as urlparse
url = "https://www.youtube.com"
browser = mechanize.Browser()
browser.open(url)
for link in browser.links():
new_url = urlparse.urljoin(link.base_url,link.url)
b1 = urlparse.urlparse(new_url).hostname
b2 = urlparse.urlparse(new_url).path
print('http://'+b1+b2)
我得到的输出:
http://accounts.google.com/ServiceLogin
<http://www.youtube.com/
http://www.youtube.com/
我期望的输出:
https://www.youtube.com/watch?v=uVvZlH5gPA
https://www.youtube.com/watch?v=uVvasdad5
【问题讨论】:
标签: python web-scraping youtube mechanize