2017-07-09 2 views
-1

Ich versuche, den einfachen Python-Code zu erhalten, um den auf der Website erwähnten mobilen Namen zurückzugeben. aber es hat nicht funktioniert. Bitte schlagen Sie mir vor, wenn Sie in einer guten Richtung sind.Web scraping - Python-Skript return []/Keine

import requests 
from bs4 
import BeautifulSoup 

url = 'https://www.flipkart.com/offers-list/new-launches?screen=dynamic&pk=themeViews%3DNewLaunches%3ADesktopView~widgetType%3DdealCard~contentType%3Dneo&wid=5.dealCard.OMU&otracker=clp_omu_New+Launches_mobiles_4' 

r = requests.get(url) 
soup = BeautifulSoup(r.content) 

mobileN = soup.find_all("div", { 
    "class", 
    "iUmrbN" 
}) 

for mo in mobileN: 
    print mo.text.strip() 

Fehler/Warnung ist wie

*** Remote Interpreter Reinitialized *** 
>>> 
C:\Python27\ArcGIS10.3\lib\site-packages\urllib3\util\ssl_.py:335: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings 
    SNIMissingWarning 
C:\Python27\ArcGIS10.3\lib\site-packages\urllib3\util\ssl_.py:133: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings 
    InsecurePlatformWarning 
C:\Python27\ArcGIS10.3\lib\site-packages\bs4\__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently. 

The code that caused this warning is on line 63 of the file C:\Users\DELL\AppData\Roaming\PyScripter\remserver.py. To get rid of this warning, change code that looks like this: 

BeautifulSoup(YOUR_MARKUP}) 

to this: 

BeautifulSoup(YOUR_MARKUP, "lxml") 

    markup_type=markup_type)) 
>>> 
+0

'Um diese Warnung loszuwerden, Code ändern, der wie folgt aussieht:' ... Lesen Sie, dass –

+0

Es tut uns leid ..! Ich poste es wieder – user1586957

Antwort

0

diesen Code Versuchen

import urllib 
import bs4 

req = urllib.request.Request('https://www.flipkart.com/offers-list/new-launches?screen=dynamic&pk=themeViews%3DNewLaunches%3ADesktopView~widgetType%3DdealCard~contentType%3Dneo&wid=5.dealCard.OMU&otracker=clp_omu_New+Launches_mobiles_4') 
content = urllib.request.urlopen(req).read() 
soup = bs4.BeautifulSoup(content, "html.parser") 

for link in soup.findAll("a"): 
    print(link.get("href")) 
+0

Es gibt Fehler, der sagt, dass das Objekt kein Attribut 'request' hat – user1586957

+0

Try import urllib.request – MishaVacic

+0

Versucht, aber immer noch der gleiche Fehler – user1586957