2017-10-26 7 views
0

ジョブのリストを.htmlファイルに保存するスクリプトを作成しました。異なるURLからデータを抽出し、lxmlを使用してリストに回答を追加します。

コードは次のとおりです。ただし

from lxml import html 
import requests 

page = requests.get('https://www.fasthosts.co.uk/careers/current-vacancies') 

content = html.fromstring(page.content) 

Vacancies = content.xpath('//h1[@class="featuredvacancy__title featuredvacancy__title--invert grid-16 alpha"]/text()') 

f = open('scrapevacancy.html', 'w') 
f.write('<br>'.join(map(str, Vacancies))) 
f.close 

、私も実行するスクリプトは、与えられた仕事のために、各URLにアクセスし「今すぐ適用」ボタンがあるかどうかを確認し、への答えを追加することで必要なものscrapevacancy.htmlの結果はそれぞれ

これはまったく可能ですか?

答えて

0
from lxml import html 
import requests 

page = requests.get('https://www.fasthosts.co.uk/careers/current-vacancies') 
content = html.fromstring(page.content) 
Vacancies = content.xpath('//h1[@class="featuredvacancy__title featuredvacancy__title--invert grid-16 alpha"]/text()') 
f = open('scrapevacancy.html', 'w') 
li = [a.attrib['href'] for a in content.xpath('//a[@class="button button__primary featuredvacancy__button"]')] 
i = 0 
for l in li: 
    p = requests.get('https://www.fasthosts.co.uk/'+l) 
    c = html.fromstring(p.content) 
    apply = c.xpath('//a[@class="button button__primary button--dtfull"]') 
    if apply: 
     f.write(str(Vacancies[i]) + ' Yes <br/>') 
    else: 
     f.write(str(Vacancies[i]) + ' No <br/') 
    i=i+1 
f.close 

出力ファイル

Developer (Java/Python) Yes
Lead Quality Assurance Engineer Yes
Senior Financial Accountant - FTC up to 12 months Yes
HR Officer Yes
HR & Training Administrator Yes
Front-End Web Developer Yes
Data Centre Operative Yes

+0

こんにちはヴァン、ご回答ありがとうございました。ただし、スクリプトは提供されたURLにアクセスし、「今すぐ適用」ボタンを確認する必要があります。ボタンがある場合、最終結果は次のようになります。 開発者(Java/Python)あり リード品質保証エンジニアNo など – klospros

+0

こんにちは、もう、ありがとうございました。私はPythonバージョン2.7.5を使用していますが、スクリプトを実行しているときに次のエラーが発生します。 ファイル "test.py"、3行目、 from urllib.request import request、urlopen ImportError:No module named request – klospros

+0

私は保証しました。その要求はpipを使ってインストールされており、 – klospros

関連する問題