Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

web scraping - html_table_parser not working in command prompt but working in python jupyter notebooks

I am running a batch file which runs my python code through the command prompt. However, when running the code it gives me the following error:

 from html_table_parser import HTMLTableParser
 ModuleNotFoundError: No module named 'html_table_parser'

However, when running my code through Jupyter-notebooks its works just fine. Is it because it isn't properly downloaded. My python.exe is found in Anaconda.

My code is the following

import urllib.request
from pprint import pprint
from html_table_parser import HTMLTableParser
import datetime
# pretty-print python data structures 
from pprint import pprint   
# for parsing all the tables present  on the website 


# for converting the parsed data in a 
# pandas dataframe 
import pandas as pd 
from bs4 import BeautifulSoup


 # Opens a website and read its 
 # binary contents (HTTP Response Body) 
  def url_get_contents(url): 

   # Opens a website and read its 
  # binary contents (HTTP Response Body) 

  #making request to the website 
  req = urllib.request.Request(url=url) 
   f = urllib.request.urlopen(req) 

   #reading contents of the website 
   return f.read() 
    xhtml = url_get_contents("https://en.wikipedia.org/wiki/Searching").decode('utf-8') 

  # Defining the HTMLTableParser object 
  p = HTMLTableParser() 

 content = urllib.request.urlopen("https://en.wikipedia.org/wiki/Searching")
  read_content = content.read()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...