程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python crawler tutorial using Python to get the channel name from the YouTube link and store it in the SQLite database (the tutorial includes the source code)

編輯:Python

Every time I want to add a new video to the database, I have to manually enter the channel name instead of just extracting it from the video URL itself (not to mention it's case sensitive).Well, this might not be the best way, but so far it worked for me and my purposes, I'll share it.

We only need BeautifulSoup and urllib for this, so let's import it now:

from bs4 import BeautifulSoup as bsfrom urllib.request import urlopen, Request

Now let's select some YouTube videos and open it with them:

url_input = "https://www.youtube.com/watch?v=pShj3gtYQik"url_opener = urlopen(Request(url_input, headers={'User-Agent': 'Mozilla'}))videoInfo = bs(url_opener, features="html.parser")

We already know how to extract the title from the previous post:

video_title = videoInfo.title.get_text()

Now, if you look at the page source for a YouTube video, you will end up with something like the following, which is what we want to access (in this case, from the video URL I used above):


So here we areÿ


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved