【问题标题】:Python scraping href adjust urlPython抓取href调整url
【发布时间】:2019-03-11 17:51:51
【问题描述】:

此代码适用于 URL http://www.schulliste.eu/schule/,但不适用于 http://www.schulliste.eu/type/gymnasien/ 有人知道为什么吗?我认为这与关键字“标题”有关 我也喜欢在它们之间使用普通的电子邮件地址(不带括号和引号),这可能吗?

import requests
from bs4 import BeautifulSoup as soup

def get_emails(_links: list, _r=[0, 10]):
    for i in range(*_r):
        new_d = soup(requests.get(_links[i]).text,         'html.parser').find_all('a', {'class':'my_modal_open'})

        if new_d:
            yield new_d[-1]['title']

d = soup(requests.get('http://www.schulliste.eu/schule/').text, 'html.parser')

results = [i['href'] for i in d.find_all('a')][52:-9]
print(list(get_emails(results)))

【问题讨论】:

    标签: python url beautifulsoup screen-scraping keyword


    【解决方案1】:
    1. 我猜是不行,b/c searched item 'a', {'class':'my_modal_open'} is not found by the second link.
    2. 要打印不带引号的内容,您可以试试这个:

    items = list(get_emails(results)) for item in items: print(item)

    【讨论】:

    • 但是第二个链接有类 my_modal_open 和一个:application_v2.just4web.cz/templates/box_email.php?email=elsterschloss-gymnasium.elsterwerda@schulen.brandenburg.de&id_lang=10&hide_email=0" class="my_modal_open" data-popup-order="0">elsterschloss-gymnasium.elsterwerdaapplication_v2.just4web.cz/img/icon_at.png" alt="E-mail" style="margin:0px;border:none;">schulen .brandenburg.de
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多