Skip to content

Commit

Permalink
add more error message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrtye committed Mar 1, 2024
1 parent 61dd469 commit 940c563
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions novel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,23 @@ def start_health_server():


def get_book_title(url, proxy=None):
html = requests.get(
url,
headers=headers,
proxies=proxy,
)
html.encoding = "gbk"
tree = etree.HTML(html.text, parser=None)

div_element = tree.xpath('//div[contains(@class, "qustime")]')[0]
span_element = div_element.xpath("./ul/li[1]/a/span")[0]
return span_element.text
try:
html = requests.get(
url,
headers=headers,
proxies=proxy,
)
html.encoding = "gbk"
tree = etree.HTML(html.text, parser=None)

div_element = tree.xpath('//div[contains(@class, "qustime")]')[0]
span_element = div_element.xpath("./ul/li[1]/a/span")[0]
return span_element.text

except Exception as e:
if proxy is None:
print("The following error occurred when using native ip")
raise e


try:
Expand Down

0 comments on commit 940c563

Please sign in to comment.