簡體   English   中英

從網站上搜索數據

[英]Scraping data from website

我在將鏈接鏈接在一起時遇到了問題。 我需要蜘蛛代碼,鏈接頁面上的鏈接,並抓住我所需的詳細信息,直到現在我的代碼能夠獲取所需的信息,但也有其他頁面,所以我需要其他頁面信息太鏈接base_url包含應用程序信息然后我想要從該頁面收集所有鏈接,然后想要切換下一頁並重復相同的事情,然后我需要收集每個應用程序的詳細信息,如他們的名稱,版本號等我從收集的鏈接
所以現在我能夠收集所有的信息只有鏈接不相互關聯我怎么能幫助我...這里是我的代碼:

#extracting links
def linkextract(soup): 
    print "\n extracting links of next pages"
    print "\n\n page 2 \n"
        sAll = [div.find('a') for div in soup.findAll('div', attrs={'class':''})]
        for i in sAll:
            suburl = ""+i['href'] #checking pages
        print suburl
        pages = mech.open(suburl)
        content = pages.read()
        anosoup = BeautifulSoup(content)
        extract(anosoup)
    app_url = ""
    print app_url
    #print soup.prettify()
    page1 = mech.open(app_url)
    html1 = page1.read()
    soup1 = BeautifulSoup(html1)
    print "\n\n application page details \n"
    extractinside(soup1)

需要幫助謝謝。

這是你應該開始的:

import urllib2
from bs4 import BeautifulSoup

URL = 'http://www.pcwelt.de/download-neuzugaenge.html'

soup = BeautifulSoup(urllib2.urlopen(URL))
links = [tr.td.a['href'] for tr in soup.find('div', {'class': 'boxed'}).table.find_all('tr') if tr.td]

for link in links:
    url = "http://www.pcwelt.de{0}".format(link)
    soup = BeautifulSoup(urllib2.urlopen(url))

    name = soup.find('span', {'itemprop': 'name'}).text
    version = soup.find('td', {'itemprop': 'softwareVersion'}).text
    print "Name: %s; Version: %s" % (name, version)

打印:

Name: Ashampoo Clip Finder HD Free; Version: 2.3.6
Name: Many Cam; Version: 4.0.63
Name: Roboform; Version: 7.9.5.7
...

希望有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM