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

Clear unnecessary text #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Apple Daily HK Crawler

## Usage
```bash
python crawl.py 20150101 20150101.json
python crawl.py 20150101 20150101.json
```

2 changes: 1 addition & 1 deletion crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def fetch(item):
root = etree.HTML(r.text)
item['title'] = root.xpath("//table[@class=\"LinkTable\"]/tr/td/h1")[0].text.strip()
item['image'] = root.xpath("//meta[@property=\"og:image\"]")[0].attrib['content'].strip()
item['text'] = ''.join([s.strip() for s in root.xpath("//div[@id=\"masterContent\"]")[0].itertext()]).strip()
item['text'] = re.sub('(please only add this icon at the end of the article)','',''.join([s.strip() for s in root.xpath("//div[@id=\"masterContent\"]")[0].itertext()]).strip())
except Exception as e:
print("cannot parse %s" % (item['link']))
raise
Expand Down