Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix download sample cases from judge.u-aizu.ac.jp #186

Merged

Conversation

hachi-88
Copy link
Contributor

@hachi-88 hachi-88 commented Nov 3, 2018

概要

AOJからのサンプルケースの取得が動作していなかったのを修正しました。

修正内容

AOJのhtmlパース時のパーサーの指定をlxmlからhtml.parserに変更しました。

補足

サンプルケースの取得が動作しなかった環境

  • macOS 10.13.6
  • Python 3.7.0
$ python3 -V
Python 3.7.0

$ pip3 -V
pip 18.0 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

$ pip3 show online-judge-tools lxml beautifulsoup4
Name: online-judge-tools
Version: 0.1.39
Summary: Tools for online-judge services
Home-page: https://github.com/kmyk/online-judge-tools
Author: Kimiyuki Onaka
Author-email: [email protected]
License: MIT License
Location: /usr/local/lib/python3.7/site-packages
Requires: requests, sympy, lxml, colorama, beautifulsoup4
Required-by:
---
Name: lxml
Version: 4.2.5
Summary: Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API.
Home-page: http://lxml.de/
Author: lxml dev team
Author-email: [email protected]
License: BSD
Location: /usr/local/lib/python3.7/site-packages
Requires:
Required-by: online-judge-tools
---
Name: beautifulsoup4
Version: 4.6.3
Summary: Screen-scraping library
Home-page: http://www.crummy.com/software/BeautifulSoup/bs4/
Author: Leonard Richardson
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.7/site-packages
Requires:
Required-by: online-judge-tools

$ brew info python
python: stable 3.7.0 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.0 (4,860 files, 103.2MB) *
  Poured from bottle on 2018-07-26 at 00:20:35
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb

@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

ありがとうございます。手元でも壊れていたことと修正できていることの両方が再現できました。
いくつか確認すべきこと確認したらマージします (なぜパーサを変えると直るのか、CI上では動いていた理由、ついでに analytic.u-aizu.ac.jp:8080 が死んでる)

@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

lxml 4.2.x だと再現しますが lxml 4.1.x だと再現しないのでlxml側のバグですね。マージします。

@kmyk kmyk merged commit 2ea89d6 into online-judge-tools:master Nov 3, 2018
@hachi-88
Copy link
Contributor Author

hachi-88 commented Nov 3, 2018

起きている現象は、下記に書かれているものと同じもののようです。

https://stackoverflow.com/questions/17859832/beautifulsoup-return-unexpected-extra-spaces

ここでもlxmlのバグだと書いてあるのですが、何年も前の書き込みなので、治ってるもんだと思ってましたが、最近デグレードしてしまったのですかね。

マージありがとうございます。m(_ _)m

@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

<meta http-equiv="Content-Type" content="text/html; charset=SHIFT-JIS" /> を含むHTML文書がUTF-8で与えられてる状況なので、バグかと言われると難しいような気もします。しかし一度はバグ扱いで修正されてるようなのでlxmlにも報告しておいた方がよさそうですね。

@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

lxml側に報告したりその準備をしたりしていますか? やらないなら私がやっておこうと思います

kmyk added a commit that referenced this pull request Nov 3, 2018
kmyk added a commit that referenced this pull request Nov 3, 2018
@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

他のページのテストしてたら html.parser だと http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2511 が落ちるが思い出されました。しかたがないのでいい感じにしておきました

@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

lxmlのそれを再現するコード:

#!/usr/bin/env python3
import bs4

html = '''<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=SHIFT-JIS" />
    <title>Title</title>
</head>
<body>
''' + '<div></div>' * 2000 + '''
</body>
</html>'''

print(bs4.BeautifulSoup(html, "lxml"))

kmyk added a commit that referenced this pull request Nov 3, 2018
kmyk added a commit that referenced this pull request Nov 3, 2018
@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

PyPIに反映させました。 pip3 install -U online-judge-tools で更新してもらえば動くようになるはずです

@kmyk
Copy link
Member

kmyk commented Nov 3, 2018

バグ報告ありがとうございました。
lxml側への報告はよろしくお願いします (しないなら私がします)。

@hachi-88
Copy link
Contributor Author

hachi-88 commented Nov 4, 2018

素早い対応ありがとうございます。
0.1.41で修正されていることが確認できました!
lxmlへの報告は準備していませんでした。お願いしてもよろしいでしょうか。m(_ _)m

@kmyk
Copy link
Member

kmyk commented Nov 4, 2018

了解です。lxmlへの報告はやっておきます。

@hachi-88 hachi-88 deleted the fix_download_sample_cases_from_aoj branch November 4, 2018 10:46
@kmyk
Copy link
Member

kmyk commented Nov 25, 2018

これ報告やるって言ったけど面倒がってまったくやってないです

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants