
我正在尝试抓取一个网站。我尝试过使用两种方法,但两种方法都没有为我提供我正在寻找的完整网站源代码。我正在尝试从下面提供的网站 url 中抓取新闻标题。
网址:“https://www.todayonline.com/”
这是我尝试过但失败的两种方法。
tdy_url = "https://www.todayonline.com/"
page = requests.get(tdy_url).text
soup = beautifulsoup(page)
soup # returns me a html with javascript text
soup.find_all('h3')
### returns me empty list []tdy_url = "https://www.todayonline.com/"
options = Options()
options.headless = True
driver = webdriver.Chrome("chromedriver",options=options)
driver.get(tdy_url)
time.sleep(10)
html = driver.page_source
soup = BeautifulSoup(html)
soup.find_all('h3')
### Returns me only less than 1/4 of the 'h3' tags found in the original page source请帮忙。我尝试过抓取其他新闻网站,这要容易得多。谢谢。
立即学习“Java免费学习笔记(深入)”;
例如,
import requests url = "https://www.todayonline.com/api/v3/news_feed/7" data = requests.get(url).json()
以上就是如何用 Python 抓取 javascript 网站?的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号