[英]Unable to scrape data from website graph using python
我正在嘗試從https://www.poder360.com.br/agregador-de-pesquisas/中抓取(解析)圖表中顯示的數據。
我已經嘗試過請求、requests-html 和 beautifulsoup,但我無法解析整個網站。 即使我單擊右鍵並查看頁面源,它也不會顯示帶有數據的表格,其 id 是“方法表”。
上次嘗試的代碼:
from requests_html import HTMLSession
def get_data(url_path):
from requests_html import HTMLSession
session = HTMLSession()
r = session.get(url_path)
r.html.render(wait = 8, sleep = 8)
return r.html
url_path = 'https://www.poder360.com.br/agregador-de-pesquisas'
content = get_data(url_path)
print(content.html)
還嘗試以下代碼
import requests
import json
from bs4 import BeautifulSoup
url = 'https://www.poder360.com.br/agregador-de-pesquisas'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
print(soup)
我認為這是因為您需要運行 Javascript 來渲染整個頁面並顯示圖形,這不適用於 HTMLSession oder 請求。
如果您在頁面的瀏覽器中單擊“檢查”並查看實時代碼而不是頁面源,則可以搜索“圓圈”並找到圖形的數據點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.