使用selenium python在youtube文本字段中输入自定义文本

使用selenium python在youtube文本字段中输入自定义文本,selenium,selenium-webdriver,beautifulsoup,selenium-ide,Selenium,Selenium Webdriver,Beautifulsoup,Selenium Ide,我正在为youtube制作一个文本刮板,我想在其中输入数据、搜索视频并收集数据。我在文本字段中输入数据时遇到问题。有人能给我推荐一种方法吗 from bs4 import BeautifulSoup driver = webdriver.Chrome() soup = BeautifulSoup(driver.page_source, 'lxml') #Use the page as source page = driver.get('https://freight.rivigo.com/

我正在为youtube制作一个文本刮板,我想在其中输入数据、搜索视频并收集数据。我在文本字段中输入数据时遇到问题。有人能给我推荐一种方法吗

from bs4 import BeautifulSoup 

driver = webdriver.Chrome()
soup = BeautifulSoup(driver.page_source, 'lxml') #Use the page as source

page = driver.get('https://freight.rivigo.com/dashboard/home')

import sys

from importlib import reload
reload


elem = driver.find_element_by_tag_name("body")

no_of_pagedowns = 120

while no_of_pagedowns:
    elem.send_keys(Keys.PAGE_DOWN)
    time.sleep(0.5)
    no_of_pagedowns-=1

soup = BeautifulSoup(driver.page_source, 'lxml')

在这段代码之间,我想在输入字段中添加一个自定义文本,比如说“喜剧”,并希望获得关于它的数据。我被困在如何输入数据的问题上,而且我对这方面很陌生,所以任何形式的帮助都会很有帮助。

该页面没有指向YouTube。查看下面的工作代码示例,了解如何使用YouTube API

# https://medium.com/greyatom/youtube-data-in-python-6147160c5833
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#from youtube_data import youtube_search


test = youtube_search("Nine Inch Nails")
test.keys()

test['commentCount'][:5]

df = pd.DataFrame(data=test)
df.head()

df1 = df[['title','viewCount','channelTitle','commentCount','likeCount','dislikeCount','tags','favoriteCount','videoId','channelId','categoryId']]
df1.columns = ['Title','viewCount','channelTitle','commentCount','likeCount','dislikeCount','tags','favoriteCount','videoId','channelId','categoryId']
df1.head()


#import numpy as np
#numeric_dtype = ['viewCount','commentCount','likeCount','dislikeCount','favoriteCount']
#for i in numeric_dtype:
#    df1[i] = df[i].astype(int)

NIN = df1[df1['channelTitle']=='Nine Inch Nails']
NIN.head()


NIN = NIN.sort_values(ascending=False,by='viewCount')
plt.bar(range(NIN.shape[0]),NIN['viewCount'])
plt.xticks(range(NIN.shape[0]),NIN['Title'],rotation=90)
plt.ylabel('viewCount in 100 millions')

plt.show()

该页面没有指向YouTube。查看下面的工作代码示例,了解如何使用YouTube API

# https://medium.com/greyatom/youtube-data-in-python-6147160c5833
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#from youtube_data import youtube_search


test = youtube_search("Nine Inch Nails")
test.keys()

test['commentCount'][:5]

df = pd.DataFrame(data=test)
df.head()

df1 = df[['title','viewCount','channelTitle','commentCount','likeCount','dislikeCount','tags','favoriteCount','videoId','channelId','categoryId']]
df1.columns = ['Title','viewCount','channelTitle','commentCount','likeCount','dislikeCount','tags','favoriteCount','videoId','channelId','categoryId']
df1.head()


#import numpy as np
#numeric_dtype = ['viewCount','commentCount','likeCount','dislikeCount','favoriteCount']
#for i in numeric_dtype:
#    df1[i] = df[i].astype(int)

NIN = df1[df1['channelTitle']=='Nine Inch Nails']
NIN.head()


NIN = NIN.sort_values(ascending=False,by='viewCount')
plt.bar(range(NIN.shape[0]),NIN['viewCount'])
plt.xticks(range(NIN.shape[0]),NIN['Title'],rotation=90)
plt.ylabel('viewCount in 100 millions')

plt.show()

你为什么不试试Youtube API呢?这里是链接的链接。这个repo将让您了解API提供的大部分功能以及它们在Python中的用法。我正在尝试编写脚本,以进一步了解web抓取。所以我想通过集成任何API来实现这一点,为什么不试试Youtube API呢?这里是链接的链接。这个repo将让您了解API提供的大部分功能以及它们在Python中的用法。我正在尝试编写脚本,以进一步了解web抓取。所以我想通过集成任何API来实现这一点