1 Random.seed (Datetime.datetime.now ())2 defgetlinks (articleurl):3html = Urlopen ("http://en.wikipedia.org"+Articleurl)4BSODJ =BeautifulSoup (HTML)5 returnBsodj.find ("Div",{"ID":"bodycontent"}). FindAll ("a", Href=re.compile ("^ (/wiki/) ((?!:).) *$"))6Links = getlinks ("/wiki/kevin_bacon")7 whileLen (links) >0:8Newarticle = Links[random.randint (0,len (links)-1)].attrs["href"]9 Print(newarticle)TenLinks = getlinks (newarticle)
This is my source code, and then I report a warning.
D:\Anaconda3\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, butifYou run this code on another system,or inchA different virtual environment, it may use a different parser andbehave differently. The code that caused this warning isOn line the file D:/thronepython/python3 network data crawl/beautifulsoup crawler _ Start Crawl/beautifulsoup Wikipedia six-degree split _ build crawler. py from one page to another. To get rid of the This warning, the change code, the looks like This:beautifulsoup ([your markup]) to This:beautifulsoup ([Your Mar Kup],"lxml") Markup_type=markup_type))
Baidu found, in fact, this is not set the default parser caused by,
Set the parser to the prompt, or take the default parser and change the fourth line to:
BSODJ = BeautifulSoup (HTML,"lxml")
Can.
Solutions for python3.x BeautifulSoup ([Your markup], "lxml") markup_type=markup_type))