0
通常,我尝试从此站点获取至少一些标记,并且始终不给出任何标记。我不知道如何解决这个问题。Python分析器输出无
有一个按钮票,从侧面按下后有一个额外的面板,所以我想解析它,我不明白如何。据我了解,点击后不会立即加载此选项卡,下一步我不明白。附:刚开始学习它。
# coding: utf-8-sig
import urllib.request
from bs4 import BeautifulSoup
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"}
def get_html(url):
request = urllib.request.Request(url,None,headers)
response = urllib.request.urlopen(request)
return response.read()
def parse(html):
soup = BeautifulSoup(html,"html.parser")
table = soup.find('body', class_='panel-open')
print(table)
def main():
parse(get_html('http://toto-info.co/'))
if __name__ == '__main__':
main()
像这样的网站有时可以在Selenium的帮助下被刮掉(*见* http://selenium-python.readthedocs.io/)。您可以使用Selenium做的一件事是使用'webdriver'的'execute_script'方法来执行Javascript代码。例如,你可以执行'document.documentElement.outerHTML'。我知道HTML5 API可以写入本地商店;不过,我还没有弄清楚细节。 –