I would like to obtain the number of comments on this Yahoo News article. I have tried the following Python code, but I have been unable to retrieve the comment count. Could anyone please advise me on how to fix this?
My code is below:
import bs4, requests
from fake_useragent import UserAgent
url = 'https://tw.news.yahoo.com/'
html = requests.get(url,headers = {'User-Agent':ua.random})
objSoup = bs4.BeautifulSoup(html.text, 'lxml')
newstitle_1 = objSoup.findAll(style = 'max-width:265px;width:calc(100% - 11px - 0px)')
result_newconn = []
for i in newstitle_1:
tt = i.get('href')
result_newconn.append(tt)
result_newconn
from selenium import webdriver
drvpath = r'c:\Users\am7420\Desktop\firefox_sele\geckodriver.exe'
browser = webdriver.Firefox(executable_path=drvpath)
browser.get(result_newconn[0])
from selenium.webdriver.common.by import By
xxpath = '//*[@id="main-0-CanvassApplet"]/div/div/div/div'
button_element = browser.find_element(By.XPATH,xxpath) #The code is interrupted at this point.
Error
>>NoSuchElementException: Unable to locate element: //*[@id="main-0-CanvassApplet"]/div/div/div/div
I would like to obtain the number of comments on this Yahoo News article.
source https://stackoverflow.com/questions/76197271/crawl-the-comment-count-of-yahoo-news
Comments
Post a Comment