大佬教程收集整理的这篇文章主要介绍了Python - 将 Webscrape 打印到 excel,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的代码可以很好地打印数据。
传统上,我会将输出保存在字典中,然后将其转换为 DataFrame,然后转换为 excel。
但是,因为我是从HTML/网站的不同部分提取数据,所以我不能使用这种方法。
如何将这 2 个数据块的输出打印到 Excel 中?
输出 - 标题,@H_196_11@m
import time
from SELEnium import webdriver
from bs4 import BeautifulSoup
import requests
from SELEnium.webdriver.Chrome.options import Options
from SELEnium.webdriver.common.by import By
from SELEnium.webdriver.support.ui import webdriverwait
from webdriver_manager.Chrome import ChromeDriveRMANager
options = Options()
driver = webdriver.Chrome(ChromeDriveRMANager().install())
url='https://www.youtube.com/user/AbbVIE/vIDeos'
driver.get(url)
last_height = driver.execute_script("return document.documentElement.scrollHeight")
SCRolL_PAUSE_TIME = 2
while True:
# Scroll down to bottom
time.sleep(2)
driver.execute_script("window.scrollTo(0,arguments[0]);",last_height)
# Wait to load page
time.sleep(SCRolL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.documentElement.scrollHeight")
if new_height == last_height:
break
last_height = new_height
content=driver.page_source.encode('utf-8').Strip()
soup=BeautifulSoup(content,'lxml')
titles = soup.findAll('a',ID='vIDeo-title')
for title in titles:
print(title.text)
Metas=soup.find_all('span',class_='style-scope ytd-grID-vIDeo-renderer')
for m in Metas:
print(m.text)
`
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Python - 将 Webscrape 打印到 excel全部内容,希望文章能够帮你解决Python - 将 Webscrape 打印到 excel所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。