我正在尝试开发一个程序,可以为传奇联盟中的某个特定冠军抓取符文。 这是我的代码:
import requests
import re
from bs4 import BeautifulSoup
url = 'https://www.leagueofgraphs.com/zh/champions/builds/darius'
response = requests.get(url).text
soup = BeautifulSoup(response,'lxml')
tables = soup.find('div',class_ = 'img-align-block')
print(tables)
这是原始HTML文件:
<img src="//cdn2.leagueofgraphs.com/img/perks/10.8/64/8010.png" alt="征服者" tooltip="<itemname><img src="//cdn2.leagueofgraphs.com/img/perks/10.8/64/8010.png" width="24" height="24" alt="征服者" /> 征服者</itemname><br/><br/>基礎攻擊或技能在命中敵方英雄時獲得 2 層征服者效果,持續 6 秒,每層效果提供 2-5 適性之力。 最多可以疊加 10 次。遠程英雄每次普攻只會提供 1 層效果。<br><br>在疊滿層數後,你對英雄造成的 15% 傷害會轉化為對自身的回復效果(遠程英雄則為 8%)。" height="36" width="36" class="requireTooltip">
我无法通过任何机会访问此部分并对其进行分析,也无法找到IMG src。不过,我可以在他们的网站上浏览。 如何解决此问题
尝试在请求的
headers
上设置一个User-Agent
,如果没有设置,网站将发送不同的内容,即:注:
您感兴趣的部分不在HTML中。您可以通过搜索进行双重检查:
网站的某些部分可能加载了JavaScript,因此您可以使用代码打开浏览器并访问该页面。例如,您可以使用selenium
该网站使用JavaScript处理,因此您需要使用Selenium或其他支持JS加载的抓取工具
相关问题 更多 >
编程相关推荐