Risen
Risen

Reputation: 19

Trying to make a small web scraper and I am getting this error

AttributeError: 'module' object has no attribute 'fromstring'

I am following along with an article which I am copying pretty much code for code with different site. I do not understand the error nor how to diagnose it. Looked up the error but haven't gotten any answers. Figure it may be a compatibility issue or small bug I cannot see.

# Web Scraper
import html
import requests

xp = '//*[@id="cont"]/pre[2]'

page = requests.get('https://tabs.ultimate-guitar.com/s/stevie_ray_vaughan/texas_flood_ver2_tab.htm')
tree = html.fromstring(page.content)

Upvotes: 0

Views: 1815

Answers (2)

Mauro Baraldi
Mauro Baraldi

Reputation: 6575

fromstring is a method from lxml lib and is used this

from lxml.html import fromstring

To check if you have lxml installed in your environment try this command:

python -c "import lxml"

If you receive some error, you need to install the lib this way:

pip install lxml

Disclaimer: You may need sudo privileges to install it.

Upvotes: 0

amiller27
amiller27

Reputation: 506

I'm guessing you meant from lxml import html instead of import html.

Upvotes: 1

Related Questions