(Mar-17-2018, 06:28 PM)tjnichols Wrote:(Mar-17-2018, 05:55 PM)snippsat Wrote: [quote="tjnichols" pid="42398" dateline="1521306539"]Can you tell me how using the requests module helps me the html? I appreciate your help!Because it's a better and easier to use than urllib in all parts,eg you get correct encoding back and security is up to date. Your script using Requests,if you look at link i gave you see use of Requests with BeautifulSoup and lxml.import requests from bs4 import BeautifulSoup url = 'http://www.pythonscraping.com/pages/page1.html' url_get = requests.get(url) soup = BeautifulSoup(url_get.content, 'html.parser') print(soup.find('title').text) print(soup.find('h1').text)[/quote Thank you! That makes sense! Let me try itI
Output:A Useful Page An Interesting Title
Hey snippsat - I tried your code. Here is what I got...
import request
from bs4 import BeautifulSoup
url = 'http://www.pythonscraping.com/pages/page1.html'
url_get = requests.get(url) soup = BeautifulSoup(url_get.content, 'html.parser')
print(soup.find('title').text)
print(soup.find('h1').text)
The error...
SyntaxError: multiple statements found while compiling a single statement
I understand things may be different as in more secure etc, what I need to understand is why I am having the issues with what I've done.
I appreciate your help and I would like to understand your way of doing things like you've shown above. Can you give me a link on the "import requests" so I can read up on that? Also, can you point me to where I can find more information on the "urllib" you talked about?
Thank you!
Tonya